Ejemplo n.º 1
0
    def create_job(self, script_name, parameter_values,
                   incoming_schedule_config, user: User):
        if user is None:
            raise InvalidUserException('User id is missing')

        config_model = self._config_service.load_config_model(
            script_name, user, parameter_values)
        self.validate_script_config(config_model)

        schedule_config = read_schedule_config(incoming_schedule_config)

        if not schedule_config.repeatable and date_utils.is_past(
                schedule_config.start_datetime):
            raise InvalidScheduleException(
                'Start date should be in the future')

        id = self._id_generator.next_id()

        job = SchedulingJob(id, user, schedule_config, script_name,
                            parameter_values)

        self.save_job(job)

        self.schedule_job(job)

        return id
Ejemplo n.º 2
0
    def schedule_job(self, job: SchedulingJob):
        schedule = job.schedule

        if not schedule.repeatable and date_utils.is_past(schedule.start_datetime):
            return

        next_datetime = schedule.get_next_time()
        LOGGER.info(
            'Scheduling ' + job.get_log_name() + ' at ' + next_datetime.astimezone(tz=None).strftime('%H:%M, %d %B %Y'))

        self.scheduler.enterabs(next_datetime.timestamp(), 1, self._execute_job, (job,))
Ejemplo n.º 3
0
    def test_when_now(self):
        value = datetime(2020, 7, 10, 15, 30, 59, 123456, tzinfo=timezone.utc)

        date_utils._mocked_now = value

        self.assertFalse(date_utils.is_past(value))
Ejemplo n.º 4
0
    def test_when_future_utc(self):
        value = datetime(2030, 7, 10, 15, 30, 59, 123456, tzinfo=timezone.utc)

        self.assertFalse(date_utils.is_past(value))
Ejemplo n.º 5
0
    def test_when_future_naive(self):
        value = datetime(2030, 7, 10, 15, 30, 59, 123456)

        self.assertFalse(date_utils.is_past(value))
Ejemplo n.º 6
0
    def test_when_past_naive(self):
        value = datetime(2020, 7, 10, 15, 30, 59, 123456)

        self.assertTrue(date_utils.is_past(value))