Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job restart #267

Merged
merged 1 commit into from
Dec 15, 2023
Merged
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
26 changes: 24 additions & 2 deletions abm/lib/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# History related functions
#

# The number of times a failed job will be restarted.
RESTART_MAX = 3

def longest_name(histories: list):
longest = 0
Expand Down Expand Up @@ -397,10 +399,21 @@ def wait(context: Context, args: list):
wait_for(gi, history_id)


def kill_all_jobs(gi: GalaxyInstance, job_list:list):
cancel_states = ['new', 'running', 'paused']
for job in job_list:
if job['state'] in cancel_states:
print(f"Cancelling job {job['tool_id']}")
gi.jobs.cancel_job(job['id'])
else:
print(f"Job {job['id']} for tool {job['tool_id']} is in state {job['state']}")


def wait_for(gi: GalaxyInstance, history_id: str):
errored = []
waiting = True
job_states = JobStates()
restart_counts = dict()
while waiting:
restart = []
status_counts = dict()
Expand All @@ -421,9 +434,18 @@ def wait_for(gi: GalaxyInstance, history_id: str):
elif state == 'error':
terminal += 1
if id not in errored:
restart.append(id)
tool = job['tool_id']
if tool in restart_counts:
restart_counts[tool] += 1
else:
restart_counts[tool] = 1
if restart_counts[tool] < RESTART_MAX:
restart.append(id)
else:
kill_all_jobs(gi, job_list)
waiting = False
errored.append(id)
if len(restart) > 0:
if len(restart) > 0 and waiting:
for job in restart:
print(f"Restaring job {job}")
try:
Expand Down