Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions pw_contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,26 @@ def patch_state_update(pw, state: dict, link: str):
log_end_sec()


def main_loop(pw) -> int:
def main_loop(pw, retries: int) -> int:
config = parse_configs()
refresh = int(config.get('cfg', 'refresh'))

try:
with open(config.get('state', 'patch_state'), "rb") as fp:
patch_state = json.load(fp)
except FileNotFoundError:
patch_state = {'series':{}, 'prs':{}}
with open(config.get('input', 'branch_info'), "rb") as fp:
branches = json.load(fp)
with open(config.get('input', 'results'), "rb") as fp:
results = json.load(fp)
with open(config.get('input', 'filters'), "rb") as fp:
filters = json.load(fp)

try:
with open(config.get('input', 'branch_info'), "rb") as fp:
branches = json.load(fp)
with open(config.get('input', 'results'), "rb") as fp:
results = json.load(fp)
with open(config.get('input', 'filters'), "rb") as fp:
filters = json.load(fp)
except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
log("Unable to read input files, retry later:", str(e))
return refresh, retries + 1

results_by_branch = results_pivot(filters, results)
branch_outcome = branch_summarize(filters, results_by_branch)
Expand All @@ -304,7 +310,7 @@ def main_loop(pw) -> int:
with open(config.get('state', 'patch_state'), 'w') as fp:
json.dump(patch_state, fp)

return int(config.get('cfg', 'refresh'))
return refresh, 0


def parse_configs():
Expand All @@ -322,11 +328,17 @@ def main() -> None:
force_single_thread=True)

pw = Patchwork(config)
retries = 0

# We could do a file system watch here, because the inputs are all local.
while True:
log("Running at " + str(datetime.datetime.now()))
delay = main_loop(pw)
delay, retries = main_loop(pw, retries)

if retries > 4:
log("Multiple succeeding errors, stop here")
sys.exit(1)

try:
time.sleep(delay)
except KeyboardInterrupt:
Expand Down
Loading