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 from_dict(job_as_dict):
    id = job_as_dict['id']
    parsed_user = user.from_serialized_dict(job_as_dict['user'])
    schedule = schedule_config.read_schedule_config(job_as_dict['schedule'])
    script_name = job_as_dict['script_name']
    parameter_values = job_as_dict['parameter_values']

    return SchedulingJob(id, parsed_user, schedule, script_name, parameter_values)