diff --git a/jobs.py b/jobs.py index c6e52292b259117722b0acc7c2e5de6b13e61d7d..1fe74bd3540af389be0813131450389fddaf3ce7 100644 --- a/jobs.py +++ b/jobs.py @@ -38,7 +38,7 @@ JOB_TRANSITIONS = [ def validTransition(fromState, toState): return (fromState + " --> " + toState) in JOB_TRANSITIONS or fromState == toState -def createJob(db, jobType, containerType, containerID): +def createJob(db, jobType, containerType, containerID, attemptN=1, previousJobID=None): """ Creates a job. @@ -63,7 +63,7 @@ def createJob(db, jobType, containerType, containerID): job = { 'state': 'pending', - 'attempt': 1, + 'attempt': attemptN, 'created': now, 'modified': now, @@ -97,6 +97,9 @@ def createJob(db, jobType, containerType, containerID): ], } + if previousJobID is not None: + job['previousJobID'] = previousJobID + result = db.jobs.insert_one(job) _id = result.inserted_id