Restart the zephyr mirroring script for new versions.

(imported from commit 860b0e120308cf190dbde2a0182e99951404cbce)
This commit is contained in:
Tim Abbott 2012-10-12 14:51:57 -04:00
parent 92496fa90f
commit e7af4a918b
2 changed files with 13 additions and 1 deletions

View file

@ -61,7 +61,7 @@ class HumbugAPI():
request["streams"] = simplejson.dumps(streams) request["streams"] = simplejson.dumps(streams)
return self.do_api_query(request, "/api/v1/subscribe") 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 max_message_id = None
while True: while True:
if max_message_id is not None: 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"])): for message in sorted(res['messages'], key=lambda x: int(x["id"])):
max_message_id = max(max_message_id, int(message["id"])) max_message_id = max(max_message_id, int(message["id"]))
callback(message) callback(message)
if idle_call is not None:
idle_call()

9
zephyr_mirror.py Normal file → Executable file
View file

@ -59,6 +59,7 @@ humbug_client = api.common.HumbugAPI(email=os.environ["USER"] + "@mit.edu",
verbose=True, verbose=True,
site=options.site) site=options.site)
start_time = time.time()
import zephyr import zephyr
zephyr.init() zephyr.init()
subs = zephyr.Subscriptions() subs = zephyr.Subscriptions()
@ -132,6 +133,11 @@ def update_subscriptions_from_humbug():
for stream in streams: for stream in streams:
ensure_subscribed(stream) 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): def process_loop(log):
sleep_count = 0 sleep_count = 0
sleep_time = 0.1 sleep_time = 0.1
@ -145,6 +151,8 @@ def process_loop(log):
traceback.print_exc() traceback.print_exc()
time.sleep(2) time.sleep(2)
maybe_restart_mirroring_script()
time.sleep(sleep_time) time.sleep(sleep_time)
sleep_count += sleep_time sleep_count += sleep_time
if sleep_count > 15: if sleep_count > 15:
@ -320,6 +328,7 @@ def humbug_to_zephyr(options):
# Sync messages from zephyr to humbug # Sync messages from zephyr to humbug
print "Starting syncing messages." print "Starting syncing messages."
humbug_client.call_on_each_message(maybe_forward_to_zephyr, humbug_client.call_on_each_message(maybe_forward_to_zephyr,
idle_call=maybe_restart_mirroring_script,
options={"mit_sync_bot": 'yes'}) options={"mit_sync_bot": 'yes'})
def subscribed_to_mail_messages(): def subscribed_to_mail_messages():