Beispiel #1
0
    def add_job(self, job_config, reconfigure=False):
        log.debug("Building new job %s", job_config.name)
        output_path = filehandler.OutputPath(self.output_stream_dir)
        scheduler = scheduler_from_config(job_config.schedule, self.time_zone)
        job = Job.from_config(job_config, scheduler, self.context, output_path)

        if job.name in self.jobs:
            # Jobs have a complex eq implementation that allows us to catch
            # jobs that have not changed and thus don't need to be updated
            # during a reconfigure
            if job == self.jobs[job.name].job:
                return

            log.info("re-adding job %s", job.name)
            self.jobs[job.name].job.update_from_job(job)
            self.jobs[job.name].schedule_reconfigured()
            return

        log.info("adding new job %s", job.name)
        self.jobs[job.name] = JobScheduler(job)
        self.event_manager.add(job, parent=self)
        self.state_watcher.watch(job, Job.NOTIFY_STATE_CHANGE)

        # If this is not a reconfigure, wait for state to be restored before
        # scheduling job runs.
        if reconfigure:
            self.jobs[job.name].schedule()
Beispiel #2
0
 def test_cron_scheduler(self):
     line = "cron */5 * * 7,8 *"
     config = schedule_parse.valid_schedule('test', line)
     sched = scheduler.scheduler_from_config(config, mock.Mock())
     start_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
     next_time = sched.next_run_time(start_time)
     assert_equal(next_time, datetime.datetime(2012, 7, 1, 0))
Beispiel #3
0
 def build(self, job_config):
     log.debug("Building new job %s", job_config.name)
     output_path = filehandler.OutputPath(self.output_stream_dir)
     scheduler = scheduler_from_config(job_config.schedule, self.time_zone)
     job = Job.from_config(job_config, scheduler, self.context, output_path,
                           self.action_runner)
     return JobScheduler(job)
Beispiel #4
0
 def test_cron_scheduler(self):
     line = "cron */5 * * 7,8 *"
     config_context = mock.Mock(path='test')
     config = schedule_parse.valid_schedule(line, config_context)
     sched = scheduler.scheduler_from_config(config=config, time_zone=None)
     start_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
     next_time = sched.next_run_time(start_time)
     assert_equal(next_time, datetime.datetime(2012, 7, 1, 0))
     assert_equal(str(sched), "cron */5 * * 7,8 *")
Beispiel #5
0
 def test_cron_scheduler(self):
     line = "cron */5 * * 7,8 *"
     config_context = mock.Mock(path='test')
     config = schedule_parse.valid_schedule(line, config_context)
     sched = scheduler.scheduler_from_config(config=config, time_zone=None)
     start_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
     next_time = sched.next_run_time(start_time)
     assert_equal(next_time, datetime.datetime(2012, 7, 1, 0))
     assert_equal(str(sched), "cron */5 * * 7,8 *")
Beispiel #6
0
 def build(self, job_config):
     log.debug(f"Building new job {job_config.name}")
     output_path = filehandler.OutputPath(self.output_stream_dir)
     time_zone = job_config.time_zone or self.time_zone
     scheduler = scheduler_from_config(job_config.schedule, time_zone)
     job = Job.from_config(
         job_config=job_config,
         scheduler=scheduler,
         parent_context=self.context,
         output_path=output_path,
         action_runner=self.action_runner,
     )
     return JobScheduler(job)
Beispiel #7
0
 def build(self, job_config):
     log.debug(f"Building new job {job_config.name}")
     output_path = filehandler.OutputPath(self.output_stream_dir)
     time_zone = job_config.time_zone or self.time_zone
     scheduler = scheduler_from_config(job_config.schedule, time_zone)
     job = Job.from_config(
         job_config=job_config,
         scheduler=scheduler,
         parent_context=self.context,
         output_path=output_path,
         action_runner=self.action_runner,
     )
     return JobScheduler(job)
Beispiel #8
0
    def test_daily_scheduler(self):
        config_context = config_utils.NullConfigContext
        line = "daily 17:32 MWF"
        config = schedule_parse.valid_schedule(line, config_context)
        sched = scheduler.scheduler_from_config(config=config, time_zone=None)
        assert_equal(sched.time_spec.hours, [17])
        assert_equal(sched.time_spec.minutes, [32])
        start_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        for day in [14, 16, 19]:
            next_time = sched.next_run_time(start_time)
            assert_equal(next_time, datetime.datetime(2012, 3, day, 17, 32))
            start_time = next_time

        assert_equal(str(sched), "daily 17:32 MWF")
Beispiel #9
0
    def test_daily_scheduler(self):
        config_context = config_utils.NullConfigContext
        line = "daily 17:32 MWF"
        config = schedule_parse.valid_schedule(line, config_context)
        sched = scheduler.scheduler_from_config(config=config, time_zone=None)
        assert_equal(sched.time_spec.hours, [17])
        assert_equal(sched.time_spec.minutes, [32])
        start_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        for day in [14, 16, 19]:
            next_time = sched.next_run_time(start_time)
            assert_equal(next_time, datetime.datetime(2012, 3, day, 17, 32))
            start_time = next_time

        assert_equal(str(sched), "daily 17:32 MWF")
Beispiel #10
0
 def build(self, job_config):
     log.debug("Building new job %s", job_config.name)
     output_path = filehandler.OutputPath(self.output_stream_dir)
     scheduler = scheduler_from_config(job_config.schedule, self.time_zone)
     job = Job.from_config(job_config, scheduler, self.context, output_path, self.action_runner)
     return JobScheduler(job)
Beispiel #11
0
def scheduler_from_config(config):
    return scheduler.scheduler_from_config(parse_groc(config), None)
Beispiel #12
0
def scheduler_from_config(config):
    return scheduler.scheduler_from_config(parse_groc(config), None)