Skip to content

Commit 9f4af54

Browse files
committed
Fix voters.json logic (broken by Chaosthebot#377)
1 parent 3e6d99c commit 9f4af54

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

cron/poll_pull_requests.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ def poll_pull_requests(api):
3636
total_votes = {}
3737
fs = fp.read()
3838
if fs:
39-
# if the voting record exists, read it in
4039
total_votes = json.loads(fs)
41-
# then prepare for overwriting
42-
fp.seek(0)
43-
fp.truncate()
4440

4541
top_contributors = sorted(gh.repos.get_contributors(api, settings.URN),
4642
key=lambda user: user["total"], reverse=True)
@@ -131,10 +127,15 @@ def poll_pull_requests(api):
131127
total_votes[user] += 1
132128
else:
133129
total_votes[user] = 1
134-
json.dump(total_votes, fp)
135130

136-
# flush all buffers because we might restart, which could cause a crash
137-
os.fsync(fp)
131+
if fs:
132+
# prepare for overwriting
133+
fp.seek(0)
134+
fp.truncate()
135+
json.dump(total_votes, fp)
136+
137+
# flush all buffers because we might restart, which could cause a crash
138+
os.fsync(fp)
138139

139140
# we approved a PR, restart
140141
if needs_update:

0 commit comments

Comments
 (0)