Skip to content

Commit

Permalink
Fix obsolete outputs function
Browse files Browse the repository at this point in the history
  • Loading branch information
madwort committed Oct 4, 2024
1 parent d93f2eb commit c97df18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion jobrunner/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from operator import attrgetter

from jobrunner.lib.database import find_all, find_one, find_where, upsert
from jobrunner.models import Flag, Job
from jobrunner.models import Flag, Job, State


def calculate_workspace_state(workspace):
Expand All @@ -19,6 +19,10 @@ def calculate_workspace_state(workspace):
for action, jobs in group_by(all_jobs, attrgetter("action")):
if action == "__error__":
continue
# Remove running jobs from the list - this function is used to compare a
# job to a previously completed job, if we include running jobs here
# we will compare a job to itself (with hilarious consequences!)
jobs = filter(lambda x: x.state != State.RUNNING, jobs)
ordered_jobs = sorted(jobs, key=attrgetter("created_at"), reverse=True)
latest_jobs.append(ordered_jobs[0])
return latest_jobs
Expand Down
6 changes: 5 additions & 1 deletion jobrunner/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,12 @@ def handle_job(job, api, mode=None, paused=None):
# final state - we have finished!
results = api.get_results(job_definition)

save_results(job, job_definition, results)
# We need to calculate obsolete before saving the results, as when we save
# the job will move to State.SUCCEEDED & then `calculate_workspace_state()`
# will mean that we are comparing results.outputs to itself (instead of
# the previous job)
obsolete = get_obsolete_files(job_definition, results.outputs)
save_results(job, job_definition, results)

if obsolete:
errors = api.delete_files(job_definition.workspace, Privacy.HIGH, obsolete)
Expand Down

0 comments on commit c97df18

Please sign in to comment.