Beispiel #1
0
 def run_job(cls, job_class_path, job_id, db_class_path, db_config,
             db_tablenames, *args, **kwargs):
     """
     :param str job_class_path: String for job class, e.g., 'myscheduler.jobs.a_job.NiceJob'
     :param str job_id: Job id
     :param str db_class_path: String for datstore class, e.g. 'datastores.DatastoreSqlite'
     :param dict db_config: dictionary containing values for db connection
     :param dict db_tablenames: dictionary containing the names for the jobs,
     executions, or audit logs table
     :param args: List of args provided to the job class to be run
     :param kwargs: Keyword arguments
     :return: string execution id
     """
     execution_id = utils.generate_uuid()
     datastore = utils.get_datastore_instance(db_class_path, db_config, db_tablenames)
     datastore.add_execution(execution_id, job_id,
                             constants.EXECUTION_STATUS_SCHEDULED,
                             description=JobBase.get_scheduled_description())
     try:
         job_class = utils.import_from_path(job_class_path)
         datastore.update_execution(execution_id, state=constants.EXECUTION_STATUS_SCHEDULED,
                                    description=job_class.get_scheduled_description())
         cls.run_scheduler_job(job_class, job_id, execution_id, datastore, *args, **kwargs)
     except Exception:
         datastore.update_execution(execution_id,
                                    state=constants.EXECUTION_STATUS_SCHEDULED_ERROR,
                                    description=JobBase.get_scheduled_error_description(),
                                    result=JobBase.get_scheduled_error_result()
                                    )
         return None
     return execution_id
Beispiel #2
0
    def add_scheduler_job(self, job_class_string, name, pub_args=None,
                          month=None, day_of_week=None, day=None,
                          hour=None, minute=None, **kwargs):
        """Add a job. Job information will be persistent in postgres.
        This is a NON-BLOCKING operation, as internally, apscheduler calls wakeup()
        that is async.
        :param str job_class_string: String for job class, e.g., myscheduler.jobs.a_job.NiceJob
        :param str name: String for job name, e.g., Check Melissa job.
        :param list pub_args: List for arguments passed to publish method of a task.
        :param str month: String for month cron string, e.g., */10
        :param str day_of_week: String for day of week cron string, e.g., 1-6
        :param str day: String for day cron string, e.g., */1
        :param str hour: String for hour cron string, e.g., */2
        :param str minute: String for minute cron string, e.g., */3
        :param dict kwargs: Other keyword arguments passed to run_job function.
        :return: String of job id, e.g., 6bca19736d374ef2b3df23eb278b512e
        :rtype: str
        Returns:
            String of job id, e.g., 6bca19736d374ef2b3df23eb278b512e
        """
        if not pub_args:
            pub_args = []

        job_id = utils.generate_uuid()
        datastore = self._lookup_jobstore('default')
        arguments = [job_class_string, job_id, self.datastore_class_path,
                     datastore.db_config, datastore.table_names]
        arguments.extend(pub_args)

        self.add_job(self.run_job,
                     'cron', month=month, day=day, day_of_week=day_of_week, hour=hour,
                     minute=minute, args=arguments, kwargs=kwargs, name=name, id=job_id)
        return job_id