]> andersk Git - jira-zephyrbot.git/blobdiff - jirabot.py
Write the new timestamp after sending Zephyrs.
[jira-zephyrbot.git] / jirabot.py
index 1c646b88eb7cedd1d7271cb55e2154f64ee48410..8c2372114b45270522ee4f23cd3e746a5d2d8362 100755 (executable)
@@ -68,6 +68,7 @@ def parse_issue(e):
     return zephyr.ZNotice(
         sender=zephyr_sender,
         auth=False,
+        opcode='auto',
         cls=zephyr_class,
         instance=issue,
         fields=[e.title, msg],
@@ -89,6 +90,7 @@ def parse_comment(e):
     return zephyr.ZNotice(
         sender=zephyr_sender,
         auth=False,
+        opcode='auto',
         cls=zephyr_class,
         instance=issue,
         fields=[e.title, msg],
@@ -98,37 +100,41 @@ def zerror(msg):
     return zephyr.ZNotice(
         sender=zephyr_sender,
         auth=False,
+        opcode='auto',
         cls=zephyr_class,
         instance='jira-error',
         fields=['Jira bot error', msg]
     )
 
 b = jira_init()
-
-jira_login(b)
-b.open("https://jira.mit.edu/jira/sr/jira.issueviews:searchrequest-rss/temp/SearchRequest.xml?&pid=10185&updated%3Aprevious=-1w&sorter/field=updated&sorter/order=DESC&tempMax=1000")
-issues_rss = b.response().read()
-b.open("https://jira.mit.edu/jira/sr/jira.issueviews:searchrequest-comments-rss/temp/SearchRequest.xml?&pid=10185&updated%3Aprevious=-1w&sorter/field=updated&sorter/order=DESC&tempMax=1000")
-comments_rss = b.response().read()
-
-time_file_new = time_file + '.' + ''.join(random.sample(string.letters, 8))
-
-try:
-    os.rename(time_file, time_file_new)
-except OSError:
-    exit()
-
-old_time = int(open(time_file_new).read())
-new_time = old_time
-
 zephyr.init()
-zephyrs = (feed_to_zephyrs('issue', issues_rss, parse_issue) +
-           feed_to_zephyrs('comment', comments_rss, parse_comment))
-
-open(time_file_new, 'w').write(str(new_time))
 
-os.rename(time_file_new, time_file)
+while True:
+    time_file_new = time_file + '.' + ''.join(random.sample(string.letters, 8))
 
-zephyrs.sort(key=lambda tz: tz[0])
-for (t, z) in zephyrs:
-    z.send()
+    try:
+        os.rename(time_file, time_file_new)
+    except OSError:
+        print "warning: could not acquire timestamp lock"
+        time.sleep(17)
+        continue
+
+    jira_login(b)
+    b.open("https://jira.mit.edu/jira/sr/jira.issueviews:searchrequest-rss/temp/SearchRequest.xml?&pid=10185&updated%3Aprevious=-1w&sorter/field=updated&sorter/order=DESC&tempMax=1000")
+    issues_rss = b.response().read()
+    b.open("https://jira.mit.edu/jira/sr/jira.issueviews:searchrequest-comments-rss/temp/SearchRequest.xml?&pid=10185&updated%3Aprevious=-1w&sorter/field=updated&sorter/order=DESC&tempMax=1000")
+    comments_rss = b.response().read()
+
+    old_time = int(open(time_file_new).read())
+    new_time = old_time
+
+    zephyrs = (feed_to_zephyrs('issue', issues_rss, parse_issue) +
+               feed_to_zephyrs('comment', comments_rss, parse_comment))
+    zephyrs.sort(key=lambda tz: tz[0])
+    for (t, z) in zephyrs:
+        z.send()
+
+    open(time_file_new, 'w').write(str(new_time))
+    os.rename(time_file_new, time_file)
+
+    time.sleep(60)
This page took 0.284136 seconds and 4 git commands to generate.