def _run_job(self, job: Job) -> None: try: super()._run_job(job) except Exception: if self.logger: self.logger.error(format_exc()) job.last_run = datetime.now() job._schedule_next_run()
def register_cron_listener(self, cron_key: str, job: schedule.Job, listener): if job and listener: instance = self def job_closure(): action = Action.create_cron_action(cron_key) action.listener = listener instance._action_queue.put(action) # no protected access, just a closure job.do(job_closure)
def _run_job(self, job: Job): try: super()._run_job(job) except Exception: self.logger.error( f"Error while {next(iter(job.tags))}...\n{format_exc()}") job.last_run = datetime.datetime.now() if not self.rerun_immediately: # Reschedule the job for the next time it was meant to run, instead of letting it run # next tick job._schedule_next_run()
def _run_job(self, job: Job): try: super()._run_job(job) except Exception: # pylint: disable=broad-except self.logger.error( f"Error while {next(iter(job.tags))}...\n{format_exc()}", notification=False) job.last_run = datetime.datetime.now() if not self.rerun_immediately: # Reschedule the job for the next time it was meant to run, instead of # letting it run # next tick job._schedule_next_run() # pylint: disable=protected-access
def schedule( self, job: pyschedule.Job, target: Callable, args: Sequence[Any] = (), kwargs: Mapping[str, Any] = {}, reenter: bool = True, ) -> None: 'Schedule a task.' log = logger[self.log_level] # type: ignore task = Task(target=target, args=args, kwargs=kwargs, reenter=reenter) log(f'Scheduling {self._format_task(job, task)}') job.do(task.run)
def format_package(pack): sub, user, granule = pack return Job( hyp3_models.Subscription(**sub), hyp3_models.User(**user), hyp3_events.NewGranuleEvent(**granule) )
def _schmain(self) -> None: for method in self._onschmethods: meth_delta: Union[float, int] = method.__schinterval__.get( 'delta', 0) if meth_delta > 0: Job(interval=meth_delta, scheduler=self._schback).seconds.do(method).tag( method.__name__) else: pass while True: with self._schlock: self._schback.run_pending() sleep(0.5)
def __schedule_job(self): self.__scheduler.clear() if in_production(): for day in self.__days: job = Job(1, self.__scheduler) job.start_day = day.name.lower() job.unit = 'weeks' job.at(self.__start_time.strftime("%H:%M")).do( self.__run_cycle) else: self.__scheduler.every(3).minutes.do(self.__run_cycle) logging.info('Next run scheduled for {0}.'.format( self.__scheduler.next_run))