From e7af4a918bed5c61fcc456492daaf5f06a597baf Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 12 Oct 2012 14:51:57 -0400 Subject: [PATCH] Restart the zephyr mirroring script for new versions. (imported from commit 860b0e120308cf190dbde2a0182e99951404cbce) --- common.py | 5 ++++- zephyr_mirror.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) mode change 100644 => 100755 zephyr_mirror.py diff --git a/common.py b/common.py index 425a7e1..294f875 100644 --- a/common.py +++ b/common.py @@ -61,7 +61,7 @@ class HumbugAPI(): request["streams"] = simplejson.dumps(streams) return self.do_api_query(request, "/api/v1/subscribe") - def call_on_each_message(self, callback, options = {}): + def call_on_each_message(self, callback, idle_call = None, options = {}): max_message_id = None while True: if max_message_id is not None: @@ -82,3 +82,6 @@ class HumbugAPI(): for message in sorted(res['messages'], key=lambda x: int(x["id"])): max_message_id = max(max_message_id, int(message["id"])) callback(message) + + if idle_call is not None: + idle_call() diff --git a/zephyr_mirror.py b/zephyr_mirror.py old mode 100644 new mode 100755 index 7f56e2a..5694b59 --- a/zephyr_mirror.py +++ b/zephyr_mirror.py @@ -59,6 +59,7 @@ humbug_client = api.common.HumbugAPI(email=os.environ["USER"] + "@mit.edu", verbose=True, site=options.site) +start_time = time.time() import zephyr zephyr.init() subs = zephyr.Subscriptions() @@ -132,6 +133,11 @@ def update_subscriptions_from_humbug(): for stream in streams: ensure_subscribed(stream) +def maybe_restart_mirroring_script(): + if os.stat("/mit/tabbott/for_friends/restart_stamp").st_mtime > start_time: + print "zephyr mirroring script has been updated; restarting..." + os.execvp("/mit/tabbott/for_friends/zephyr_mirror.py", sys.argv) + def process_loop(log): sleep_count = 0 sleep_time = 0.1 @@ -145,6 +151,8 @@ def process_loop(log): traceback.print_exc() time.sleep(2) + maybe_restart_mirroring_script() + time.sleep(sleep_time) sleep_count += sleep_time if sleep_count > 15: @@ -320,6 +328,7 @@ def humbug_to_zephyr(options): # Sync messages from zephyr to humbug print "Starting syncing messages." humbug_client.call_on_each_message(maybe_forward_to_zephyr, + idle_call=maybe_restart_mirroring_script, options={"mit_sync_bot": 'yes'}) def subscribed_to_mail_messages():