def save_results(job, definition, results): """Extract the results of the execution and update the job accordingly.""" # set the final state of the job if results.exit_code != 0: job.state = State.FAILED job.status_message = f"Job exited with error code {results.exit_code}" job.status_code = StatusCode.NONZERO_EXIT if results.message: job.status_message += f": {results.message}" elif definition.allow_database_access: error_msg = config.DATABASE_EXIT_CODES.get(results.exit_code) if error_msg: job.status_message += f": {error_msg}" elif results.unmatched_patterns: job.state = State.FAILED job.status_message = "No outputs found matching patterns:\n - {}".format( "\n - ".join(results.unmatched_patterns)) # If the job fails because an output was missing its very useful to # show the user what files were created as often the issue is just a # typo job.unmatched_outputs = results.unmatched_outputs else: job.state = State.SUCCEEDED job.status_message = "Completed successfully" job.outputs = results.outputs job.updated_at = int(time.time()) update(job)
def test_update_excluding_a_field(tmp_work_dir): job = Job(id="foo123", action="foo", commit="commit-of-glory") insert(job) job.action = "bar" job.commit = "commit-of-doom" update(job, exclude_fields=["commit"]) j = find_one(Job, id="foo123") assert j.action == "bar" assert j.commit == "commit-of-glory"
def main(partial_job_id): job = get_job(partial_job_id) if not docker.container_exists(container_name(job)): raise RuntimeError( "Cannot reset job, associated container does not exist") job.state = State.RUNNING job.status_message = "Re-attempting to extract outputs" job.status_code = None job.completed_at = None job.updated_at = int(time.time()) print("\nUpdating job in database:") print(job) update(job) print("\nPOSTing update to job-server") api_post("jobs", json=[job_to_remote_format(job)]) print("\nDone")
def update_job(job): # The cancelled field is written by the sync thread and we should never update it. The sync thread never updates # any other fields after it has created the job, so we're always safe to modify them. update(job, exclude_fields=["cancelled"])
def test_update(tmp_work_dir): job = Job(id="foo123", action="foo") insert(job) job.action = "bar" update(job) assert find_one(Job, id="foo123").action == "bar"