def stop_job(self, job_id): job = Job(self.db) job.update_status(job_id, "stop") try: self.scheduler.remove_job("job." + job_id) except: pass
def start_job(self, job_id): job = Job(self.db) job_class = job.find(job_id) if (job_class == None): return None task_class = job_class["task"] if (task_class == None): return None timer_class = job_class["timer"] if (timer_class == None): return None job_id = job_class["id"] job.update_status(job_id, "active") self.scheduler.add_job(func=SchedulerJobExector({ "scheduler": self, "task": task_class, "timer": timer_class, "job_id": job_id, }), trigger=timer_class["type"], id="job." + job_id, **timer_class["param"], misfire_grace_time=3600, coalesce=True) return True
def onJobResult(self, content, status, message): job = Job(self.db) job_id = content["job_id"] if status == "success": result = { "status": status, } else: result = { "status": status, "message": message, } job.set_result(job_id, result) loop = False if ("timer" in content): loop = True if not loop: job.update_status(job_id, "complete")