[ARVADOS] created: ca8e8224203ba5be3a9a190862e7c8ac2ac94e7e

git at public.curoverse.com git at public.curoverse.com
Wed Jul 15 23:28:29 EDT 2015


        at  ca8e8224203ba5be3a9a190862e7c8ac2ac94e7e (commit)


commit ca8e8224203ba5be3a9a190862e7c8ac2ac94e7e
Merge: 7748c0b 7365909
Author: radhika <radhika at curoverse.com>
Date:   Wed Jul 15 23:28:06 2015 -0400

    Merge branch 'master' into 6473-fetch-events-starting-at


commit 7748c0b5eb966b8d05eb2156b4445f552ed3839d
Author: radhika <radhika at curoverse.com>
Date:   Wed Jul 15 23:23:47 2015 -0400

    6473: add start_time additional argument to arv-ws

diff --git a/sdk/python/arvados/commands/ws.py b/sdk/python/arvados/commands/ws.py
index 9bce997..26d528a 100644
--- a/sdk/python/arvados/commands/ws.py
+++ b/sdk/python/arvados/commands/ws.py
@@ -14,6 +14,7 @@ def main(arguments=None):
     parser = argparse.ArgumentParser()
     parser.add_argument('-u', '--uuid', type=str, default="", help="Filter events on object_uuid")
     parser.add_argument('-f', '--filters', type=str, default="", help="Arvados query filter to apply to log events (JSON encoded)")
+    parser.add_argument('-s', '--start_time', type=str, default="", help="Arvados query filter to apply to log events created after this time. Allowed format: YYYY-MM-DD or YYYY-MM-DD hh:mm:ss")
 
     group = parser.add_mutually_exclusive_group()
     group.add_argument('--poll-interval', default=15, type=int, help="If websockets is not available, specify the polling interval, default is every 15 seconds")
@@ -60,6 +61,9 @@ def main(arguments=None):
     if args.pipeline:
         filters += [ ['object_uuid', '=', args.pipeline] ]
 
+    if args.start_time:
+        filters += [ ['created_at', '>', args.start_time] ]
+
     def on_message(ev):
         global filters
         global ws
diff --git a/sdk/python/tests/test_arv_ws.py b/sdk/python/tests/test_arv_ws.py
new file mode 100644
index 0000000..5a01827
--- /dev/null
+++ b/sdk/python/tests/test_arv_ws.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+import unittest
+import arvados.errors as arv_error
+import arvados.commands.ws as arv_ws
+
+class ArvWsTestCase(unittest.TestCase):
+    def run_ws(self, args):
+        return arv_ws.main(args)
+
+    def test_unsupported_arg(self):
+        with self.assertRaises(SystemExit):
+            self.run_ws(['-x=unknown'])
diff --git a/sdk/python/tests/test_websockets.py b/sdk/python/tests/test_websockets.py
index d879ebe..6889c6f 100644
--- a/sdk/python/tests/test_websockets.py
+++ b/sdk/python/tests/test_websockets.py
@@ -5,6 +5,7 @@ import arvados
 import arvados.events
 import mock
 import threading
+from datetime import datetime, timedelta
 
 class WebsocketTest(run_test_server.TestCaseWithServers):
     MAIN_SERVER = {}
@@ -17,11 +18,14 @@ class WebsocketTest(run_test_server.TestCaseWithServers):
             self.ws.close()
         super(WebsocketTest, self).tearDown()
 
-    def _test_subscribe(self, poll_fallback, expect_type):
+    def _test_subscribe(self, poll_fallback, expect_type, additional_filters=None):
         run_test_server.authorize_with('active')
         events = Queue.Queue(3)
+        filters = [['object_uuid', 'is_a', 'arvados#human']]
+        if additional_filters:
+            filters = filters + additional_filters
         self.ws = arvados.events.subscribe(
-            arvados.api('v1'), [['object_uuid', 'is_a', 'arvados#human']],
+            arvados.api('v1'), filters,
             events.put, poll_fallback=poll_fallback)
         self.assertIsInstance(self.ws, expect_type)
         self.assertEqual(200, events.get(True, 10)['status'])
@@ -33,6 +37,25 @@ class WebsocketTest(run_test_server.TestCaseWithServers):
         self._test_subscribe(
             poll_fallback=False, expect_type=arvados.events.EventClient)
 
+    def test_subscribe_websocket_with_start_time_today(self):
+        lastHour = datetime.today() - timedelta(hours = 1)
+        self._test_subscribe(
+            poll_fallback=False, expect_type=arvados.events.EventClient,
+                additional_filters=[['created_at', '>', lastHour.strftime('%Y-%m-%d')]])
+
+    def test_subscribe_websocket_with_start_time_last_hour(self):
+        lastHour = datetime.today() - timedelta(hours = 1)
+        self._test_subscribe(
+            poll_fallback=False, expect_type=arvados.events.EventClient,
+                additional_filters=[['created_at', '>', lastHour.strftime('%Y-%m-%d %H:%M:%S')]])
+
+    def test_subscribe_websocket_with_start_time_next_hour(self):
+        nextHour = datetime.today() + timedelta(hours = 1)
+        with self.assertRaises(Queue.Empty):
+            self._test_subscribe(
+                poll_fallback=False, expect_type=arvados.events.EventClient,
+                    additional_filters=[['created_at', '>', nextHour.strftime('%Y-%m-%d %H:%M:%S')]])
+
     @mock.patch('arvados.events.EventClient.__init__')
     def test_subscribe_poll(self, event_client_constr):
         event_client_constr.side_effect = Exception('All is well')

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list