コード例 #1
0
    def test_modify_job(self):
        headers = {'Content-Type': 'application/json; charset=UTF-8'}
        data = {
            'job_class_string': 'hello.world',
            'name': 'hello world job',
            'minute': '*/5'
        }
        response = self.fetch(self.JOBS_URL,
                              method='POST',
                              headers=headers,
                              body=json.dumps(data))
        return_info = json.loads(response.body.decode())
        self.assertTrue('job_id' in return_info)
        self.assertEquals(len(return_info['job_id']), 32)
        job = self.scheduler.get_job(return_info['job_id'])
        self.assertEquals(utils.get_job_name(job), data['job_class_string'])
        self.assertEquals(job.name, data['name'])

        headers = {'Content-Type': 'application/json; charset=UTF-8'}
        data = {
            'job_class_string': 'hello.world!!!!',
            'name': 'hello world job~~~~',
            'minute': '*/100'
        }
        response = self.fetch(self.JOBS_URL + '/' + return_info['job_id'] +
                              '?sync=true',
                              method='PUT',
                              headers=headers,
                              body=json.dumps(data))
        self.assertEquals(response.code, 200)
        job = self.scheduler.get_job(return_info['job_id'])
        self.assertEquals(utils.get_job_name(job), data['job_class_string'])
        self.assertEquals(job.name, data['name'])
コード例 #2
0
ファイル: jobs_test.py プロジェクト: alexchao56/ndscheduler
    def test_modify_job(self):
        headers = {'Content-Type': 'application/json; charset=UTF-8'}
        data = {
            'job_class_string': 'hello.world',
            'name': 'hello world job',
            'minute': '*/5'}
        response = self.fetch(self.JOBS_URL, method='POST', headers=headers,
                              body=json.dumps(data))
        return_info = json.loads(response.body)
        self.assertTrue('job_id' in return_info)
        self.assertEquals(len(return_info['job_id']), 32)
        job = self.scheduler.get_job(return_info['job_id'])
        self.assertEquals(utils.get_job_name(job), data['job_class_string'])
        self.assertEquals(job.name, data['name'])

        headers = {'Content-Type': 'application/json; charset=UTF-8'}
        data = {
            'job_class_string': 'hello.world!!!!',
            'name': 'hello world job~~~~',
            'minute': '*/100'}
        response = self.fetch(self.JOBS_URL + '/' + return_info['job_id'] + '?sync=true',
                              method='PUT', headers=headers, body=json.dumps(data))
        self.assertEquals(response.code, 200)
        job = self.scheduler.get_job(return_info['job_id'])
        self.assertEquals(utils.get_job_name(job), data['job_class_string'])
        self.assertEquals(job.name, data['name'])
コード例 #3
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
コード例 #4
0
ファイル: base.py プロジェクト: alexchao56/ndscheduler
    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
コード例 #5
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
コード例 #6
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
コード例 #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