def getNewRunningInstance(self, job, runningAttrs=None): """ create a new RunningInstance """ if runningAttrs is None: run = RunningJob() else: run = RunningJob(runningAttrs) job.newRunningInstance(run, self.db)
def removeTask(self, task): """ remove task, jobs and their running instances from db """ # db connect if self.db is None: self.connect() # remove jobs in db with non relational checks if self.bossLiteDB.database == "SQLite": # load running jobs rjob = RunningJob({'taskId': task['id']}) rjobList = self.db.select(rjob) for rjob in rjobList: rjob.remove(self.db) # load jobs job = Job({'taskId': task['id']}) jobList = self.db.select(job) for job in jobList: job.remove(self.db) # remove task task.remove(self.db) self.bossLiteDB.commit() task = None return task
def removeJob(self, job): """ remove job and its running instances from db """ # db connect if self.db is None: self.connect() # remove runnningjobs in db with non relational checks if self.bossLiteDB.database == "SQLite": # load running jobs rjob = RunningJob({'jobId': job['jobId'], 'taskId': job['taskId']}) rjobList = self.db.select(rjob) for rjob in rjobList: rjob.remove(self.db) # remove job job.remove(self.db) self.bossLiteDB.commit() job = None return job
def getRunningInstance(self, db): """ get running job information """ # create template template = RunningJob() template['jobId'] = self['jobId'] template['taskId'] = self['taskId'] template['submission'] = self['submissionNumber'] # template['closed'] = "N" # get running job runningJobs = db.select(template) # no running instance if runningJobs == []: self.runningJob = None # one running instance elif len(runningJobs) == 1: self.runningJob = runningJobs[0] # oops, more than one! else: raise JobError("Multiple running instances of job %s : %s" % \ (self['jobId'], len(runningJobs)))
def loadJobsByTimestamp(self, more, less, runningAttrs=None, jobAttributes=None): """ retrieve job information from db for job whose running instance match attributes """ # db connect if self.db is None: self.connect() # creating running jobs if runningAttrs is None: run = RunningJob() else: run = RunningJob(runningAttrs) # creating jobs if jobAttributes is None: job = Job() else: job = Job(jobAttributes) # load job from db jMap = { 'jobId': 'jobId', 'taskId': 'taskId', 'submissionNumber': 'submission' } runJobList = self.db.selectJoin( job, run, \ jMap=jMap, \ less=less, \ more=more ) # recall jobs for job, runningJob in runJobList: job.setRunningInstance(runningJob) # return return [key[0] for key in runJobList]
def loadRunJobDistinct(self, taskId, distinctAttr, jobAttributes=None): """ retrieve job templates with distinct job attribute """ # db connect if self.db is None: self.connect() # creating job if jobAttributes is None: job = RunningJob() else: job = RunningJob(jobAttributes) job['taskId'] = taskId # load job from db jobList = self.db.selectDistinct(job, distinctAttr) return jobList
def getRunningInstance(self, job, runningAttrs=None): """ retrieve RunningInstance where existing or create it """ # check whether the running instance is still loaded if job.runningJob is not None: return # load if exixts job.getRunningInstance(self.db) # create it otherwise if job.runningJob is None: if runningAttrs is None: run = RunningJob() else: run = RunningJob(runningAttrs) job.newRunningInstance(run, self.db)
def closeRunningInstance(self, db): """ close the running instance. it should be only one but ignore if there are more than one... """ # do not do anything if the job is not completely defined if not self.valid(['jobId', 'taskId']): return # create template template = RunningJob() template['jobId'] = self['jobId'] template['taskId'] = self['taskId'] template['closed'] = "N" # get running job runningJobs = db.select(template) # do for all of them (should be one...) for job in runningJobs: job["closed"] = "Y" job.update(db)
def loadJobsByRunningAttr(self, runningAttrs=None, jobAttributes=None, all=False, strict=True, limit=None, offset=None, jobList=None): """ retrieve job information from db for job whose running instance match attributes """ # db connect if self.db is None: self.connect() # creating running jobs if runningAttrs is None: run = RunningJob() else: run = RunningJob(runningAttrs) # creating jobs if jobAttributes is None: job = Job() else: job = Job(jobAttributes) # if requested, with a right join is possible to fill a running # instance where missing if all: jType = 'right' else: jType = '' # load bunch of jobs? if jobList is None or jobList == []: inList = None else: inList = {'jobId': jobList} # load job from db jMap = { 'jobId': 'jobId', 'taskId': 'taskId', 'submissionNumber': 'submission' } options = { 'strict': strict, 'jType': jType, 'limit': limit, 'offset': offset, 'inList': inList } runJobList = self.db.selectJoin( job, run, \ jMap=jMap , \ options=options ) # recall jobs for job, runningJob in runJobList: job.setRunningInstance(runningJob) # return return [key[0] for key in runJobList]