[ARVADOS] created: 3e5e5fa67a8f548397bda99449c7f7b19fadc641

git at public.curoverse.com git at public.curoverse.com
Thu Jan 8 16:31:11 EST 2015


        at  3e5e5fa67a8f548397bda99449c7f7b19fadc641 (commit)


commit 3e5e5fa67a8f548397bda99449c7f7b19fadc641
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Thu Jan 8 16:32:41 2015 -0500

    4904: Add feature to arv-ws to run a command when something is added or removed from a project

diff --git a/sdk/python/arvados/commands/ws.py b/sdk/python/arvados/commands/ws.py
index 04e3f64..b6ad029 100644
--- a/sdk/python/arvados/commands/ws.py
+++ b/sdk/python/arvados/commands/ws.py
@@ -7,6 +7,7 @@ import arvados
 import json
 from arvados.events import subscribe
 import signal
+import subprocess
 
 def main(arguments=None):
     logger = logging.getLogger('arvados.arv-ws')
@@ -22,6 +23,9 @@ def main(arguments=None):
     group = parser.add_mutually_exclusive_group()
     group.add_argument('-p', '--pipeline', type=str, default="", help="Supply pipeline uuid, print log output from pipeline and its jobs")
     group.add_argument('-j', '--job', type=str, default="", help="Supply job uuid, print log output from jobs")
+    group.add_argument('--project', type=str, default="", help="Monitor change events for a specific project")
+
+    parser.add_argument('--command', type=str, default="", help="Command to run when project event occurs")
 
     args = parser.parse_args(arguments)
 
@@ -79,9 +83,29 @@ def main(arguments=None):
                 if ev["object_kind"] == "arvados#job" and args.job:
                     if ev["properties"]["new_attributes"]["state"] in ("Complete", "Failed", "Cancelled"):
                         ws.close()
-        elif 'status' in ev and ev['status'] == 200:
-            pass
-        else:
+            return
+
+        if 'status' in ev and ev['status'] == 200:
+            return
+
+        if args.project:
+            old_attr = None
+            if 'old_attributes' in ev['properties'] and ev['properties']['old_attributes']:
+                old_attr = ev['properties']['old_attributes']
+            if args.project not in (ev['properties']['new_attributes']['owner_uuid'],
+                                    old_attr['owner_uuid'] if old_attr else None):
+                return
+
+            if args.command:
+                et = ev['event_type']
+                if ev['event_type'] == 'update' and ev['properties']['new_attributes']['owner_uuid'] != ev['properties']['old_attributes']['owner_uuid']:
+                    if args.project == ev['properties']['new_attributes']['owner_uuid']:
+                        et = 'add'
+                    else:
+                        et = 'remove'
+                subprocess.call([args.command, args.project, et, ev['object_uuid']])
+                return
+
             print json.dumps(ev)
 
     try:
diff --git a/sdk/python/arvados/events.py b/sdk/python/arvados/events.py
index d1abc0f..1feb1fe 100644
--- a/sdk/python/arvados/events.py
+++ b/sdk/python/arvados/events.py
@@ -48,6 +48,7 @@ class EventClient(WebSocketClient):
 class PollClient(threading.Thread):
     def __init__(self, api, filters, on_event, poll_time):
         super(PollClient, self).__init__()
+        self.daemon = True
         self.api = api
         if filters:
             self.filters = [filters]
@@ -79,7 +80,8 @@ class PollClient(threading.Thread):
             self.stop.wait(self.poll_time)
 
     def run_forever(self):
-        self.stop.wait()
+        while not self.stop.is_set():
+            self.stop.wait(1)
 
     def close(self):
         self.stop.set()

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list