def setup_job(self, job_id: int): # method that clean some garbage if self.current_job is not None: self.current_job.status = JobPeewee.STATUS_DONE self.current_job.save() self.current_job = JobPeewee.get(JobPeewee.id == job_id) self.current_job.status = JobPeewee.STATUS_RUNNING self.current_job.save()
def get_running_job(): ret = Core.get_lock(JobDataModel.LOCK) if not ret: return None else: job_id = int(ret) try: job = JobDataModel.get(JobDataModel.id == job_id) return job except JobDataModel.DoesNotExist: return None
def is_job_alive(core, job_id): try: obj = JobDataModel.get(JobDataModel.id == job_id) # may be wrong logging.debug("find possible alive task %i pid is %i %s" % (job_id, obj.pid, obj.status)) if obj.status == JobDataModel.STATUS_EXCEPTION: return False if obj.status == JobDataModel.STATUS_FAILED: return False if obj.status == JobDataModel.STATUS_DONE: return False pid = obj.pid return core.api.os.shell.is_alive(pid) except JobDataModel.DoesNotExist: return False