def run_job(job_id): job = fetch(Job, id=job_id) now = datetime.now() + timedelta(seconds=5) scheduler.add_job(id=str(now), func=scheduler_job, run_date=now, args=[job_id], trigger='date') return jsonify(job.serialized)
def recurrent_scheduling(self): if not self.start_date: self.start_date = datetime.now() + timedelta(seconds=15) # run the job on a regular basis with an interval trigger scheduler.add_job(id=self.creation_time, func=self.job, args=[self.name], trigger='interval', start_date=self.start_date, end_date=self.end_date, seconds=int(self.frequency), replace_existing=True)
def schedule(self): if self.frequency: scheduler.add_job(id=self.creation_time, func=scheduler_job, args=[self.job.id], trigger='interval', start_date=self.aps_date('start_date'), end_date=self.aps_date('end_date'), seconds=int(self.frequency), replace_existing=True) else: scheduler.add_job(id=self.creation_time, func=scheduler_job, run_date=self.aps_date('start_date'), args=[self.job.id], trigger='date', replace_existing=True)
def schedule(self, run_now=True): now = datetime.now() + timedelta(seconds=15) runtime = now if run_now else self.start_date if self.frequency: scheduler.add_job(id=self.creation_time, func=job, args=[self.name, str(runtime)], trigger='interval', start_date=runtime, end_date=self.end_date, seconds=int(self.frequency), replace_existing=True) else: scheduler.add_job(id=str(runtime), run_date=runtime, func=job, args=[self.name, str(runtime)], trigger='date') return str(runtime)
def run(self, run_now=True): runtime = datetime.now() + timedelta(seconds=5) if not run_now and not self.start_date: # when the job is scheduled to run immediately, it may happen that # the job is run even before the task is created, in which case # it fails because it cannot be retrieve from the Task column of # the database: we introduce a delta of 5 seconds. # other situation: the server is too slow and the job cannot be # run at all, eg 'job was missed by 0:00:09.465684' self.start_date = runtime # execute the job immediately with a date-type job # when date is used as a trigger and run_date is left undetermined, # the job is executed immediately. run_date = self.start_date or runtime scheduler.add_job(id=self.creation_time, run_date=run_date, func=workflow_job, args=[self.name], trigger='date')
def run_job(job_id): job = fetch('Job', id=job_id) if job.status == 'Running': return {'error': 'Job is already running.'} targets = job.compute_targets() if hasattr(job, 'has_targets'): if job.has_targets and not targets: return {'error': 'Set devices or pools as targets first.'} if not job.has_targets and targets: return { 'error': 'This service should not have targets configured.' } job.status, job.state = 'Running', {} info(f'{job.name}: starting.') db.session.commit() scheduler.add_job(id=str(datetime.now()), func=scheduler_job, run_date=datetime.now(), args=[job_id], trigger='date') return job.serialized
def schedule(self): default, trigger = self.kwargs() scheduler.add_job(**{**default, **trigger})