Esempio n. 1
0
    def _build_execution(self, row):
        """Return job execution info from a row of scheduler_execution table.

        :param obj row: A row instance of scheduler_execution table.
        :return: A dictionary of job execution info.
        :rtype: dict
        """
        # To avoid circular import

        return_json = {
            'execution_id': row.eid,
            'state': constants.EXECUTION_STATUS_DICT[row.state],
            'hostname': row.hostname,
            'pid': row.pid,
            'task_id': row.task_id,
            'description': row.description,
            'scheduled_time': self.get_time_isoformat_from_db(row.scheduled_time),
            'updated_time': self.get_time_isoformat_from_db(row.updated_time)}
        job = self.lookup_job(row.job_id)
        if job:
            return_json['job'] = {
                'job_id': job.id,
                'name': job.name,
                'task_name': utils.get_job_name(job),
                'pub_args': utils.get_job_args(job)}
            return_json['job'].update(utils.get_cron_strings(job))
        return return_json
Esempio n. 2
0
    def _build_execution(self, row):
        """Return job execution info from a row of scheduler_execution table.

        :param obj row: A row instance of scheduler_execution table.
        :return: A dictionary of job execution info.
        :rtype: dict
        """
        # To avoid circular import

        return_json = {
            'execution_id': row.eid,
            'state': constants.EXECUTION_STATUS_DICT[row.state],
            'hostname': row.hostname,
            'pid': row.pid,
            'task_id': row.task_id,
            'description': row.description,
            'scheduled_time':
            self.get_time_isoformat_from_db(row.scheduled_time),
            'updated_time': self.get_time_isoformat_from_db(row.updated_time)
        }
        job = self.lookup_job(row.job_id)
        if job:
            return_json['job'] = {
                'job_id': job.id,
                'name': job.name,
                'task_name': utils.get_job_name(job),
                'pub_args': utils.get_job_args(job)
            }
            return_json['job'].update(utils.get_cron_strings(job))
        return return_json
Esempio n. 3
0
    def _run_job(self, job_id):
        """Kicks off a job.

        :param str job_id: Job id.

        :return: A dictionary with the only field of execution_id.
        :rtype: dict
        """

        job = self.scheduler_manager.get_job(job_id)
        if not job:
            self.set_status(400)
            return {'error': 'Job not found: %s' % job_id}
        job_name = utils.get_job_name(job)
        args = utils.get_job_args(job)
        kwargs = job.kwargs
        execution_id = scheduler_base.SingletonScheduler.run_job(job_name,
                                                                 job_id, *args, **kwargs)

        # Audit log
        self.datastore.add_audit_log(job_id, job.name, constants.AUDIT_LOG_CUSTOM_RUN,
                                     self.username, execution_id)

        response = {
            'execution_id': execution_id}
        return response
    def test_add_job_get_job(self):
        task_name = 'hello.world'
        name = 'it is hello world'
        pub_args = ('1', '2', '3')
        month = '*/1'
        day_of_week = 'sat'
        day = '*/2'
        hour = '*/3'
        minute = '*/4'

        # non-blocking operation
        job_id = self.scheduler.add_job(task_name,
                                        name,
                                        pub_args,
                                        month,
                                        day_of_week,
                                        day,
                                        hour,
                                        minute,
                                        languages='en-us')

        self.assertTrue(len(job_id), 32)

        # blocking operation
        job = self.scheduler.get_job(job_id)
        self.assertEqual(self.scheduler.get_job_task_class(job), task_name)
        self.assertEqual(job.id, job_id)
        self.assertEqual(job.name, name)
        self.assertEqual(utils.get_job_args(job), pub_args)
        self.assertEqual(utils.get_job_kwargs(job), {'languages': 'en-us'})

        # Year
        self.assertEquals(unicode(job.trigger.fields[0]), '*')
        # Month
        self.assertEquals(unicode(job.trigger.fields[1]), month)
        # day of month
        self.assertEquals(unicode(job.trigger.fields[2]), day)
        # week
        self.assertEquals(unicode(job.trigger.fields[3]), '*')
        # day of week
        self.assertEquals(unicode(job.trigger.fields[4]), day_of_week)
        # hour
        self.assertEquals(unicode(job.trigger.fields[5]), hour)
        # minute
        self.assertEquals(unicode(job.trigger.fields[6]), minute)
        # second
        self.assertEquals(unicode(job.trigger.fields[7]), '0')
Esempio n. 5
0
    def _build_job_dict(self, job):
        """Transforms apscheduler's job structure to a python dictionary.

        :param Job job: An apscheduler.job.Job instance.
        :return: dictionary for job info
        :rtype: dict
        """
        if job.next_run_time:
            next_run_time = job.next_run_time.isoformat()
        else:
            next_run_time = ''
        return_dict = {
            'job_id': job.id,
            'name': job.name,
            'next_run_time': next_run_time,
            'job_class_string': utils.get_job_name(job),
            'pub_args': utils.get_job_args(job)}

        return_dict.update(utils.get_cron_strings(job))
        return return_dict
    def test_add_job_get_job(self):
        task_name = 'hello.world'
        name = 'it is hello world'
        pub_args = ('1', '2', '3')
        month = '*/1'
        day_of_week = 'sat'
        day = '*/2'
        hour = '*/3'
        minute = '*/4'

        # non-blocking operation
        job_id = self.scheduler.add_job(task_name, name, pub_args, month, day_of_week, day,
                                        hour, minute, languages='en-us')

        self.assertTrue(len(job_id), 32)

        # blocking operation
        job = self.scheduler.get_job(job_id)
        self.assertEqual(self.scheduler.get_job_task_class(job), task_name)
        self.assertEqual(job.id, job_id)
        self.assertEqual(job.name, name)
        self.assertEqual(utils.get_job_args(job), pub_args)
        self.assertEqual(utils.get_job_kwargs(job), {'languages': 'en-us'})

        # Year
        self.assertEquals(str(job.trigger.fields[0]), '*')
        # Month
        self.assertEquals(str(job.trigger.fields[1]), month)
        # day of month
        self.assertEquals(str(job.trigger.fields[2]), day)
        # week
        self.assertEquals(str(job.trigger.fields[3]), '*')
        # day of week
        self.assertEquals(str(job.trigger.fields[4]), day_of_week)
        # hour
        self.assertEquals(str(job.trigger.fields[5]), hour)
        # minute
        self.assertEquals(str(job.trigger.fields[6]), minute)
        # second
        self.assertEquals(str(job.trigger.fields[7]), '0')
Esempio n. 7
0
    def _build_job_dict(self, job):
        """Transforms apscheduler's job structure to a python dictionary.

        :param Job job: An apscheduler.job.Job instance.
        :return: dictionary for job info
        :rtype: dict
        """
        if job.next_run_time:
            next_run_time = job.next_run_time.isoformat()
        else:
            next_run_time = ""
        return_dict = {
            "job_id": job.id,
            "name": job.name,
            "next_run_time": next_run_time,
            "job_class_string": utils.get_job_name(job),
            "pub_args": utils.get_job_args(job),
        }

        return_dict.update(utils.get_job_kwargs(job))
        return_dict.update(utils.get_cron_strings(job))
        return return_dict