def test_existing_job(self): """ Test cancelling an existing job. """ job1 = self.enqueue(queue=u"q") job2 = self.enqueue(queue=u"q") with helpers.recorded_logs(u"ckan.logic") as logs: helpers.call_action(u"job_cancel", id=job1.id) all_jobs = self.all_jobs() assert len(all_jobs) == 1 assert all_jobs[0] == job2 with pytest.raises(KeyError): jobs.job_from_id(job1.id) logs.assert_log(u"info", re.escape(job1.id))
def job_cancel(context, data_dict): '''Cancel a queued background job. Removes the job from the queue and deletes it. :param string id: The ID of the background job. .. versionadded:: 2.7 ''' _check_access(u'job_cancel', context, data_dict) id = _get_or_bust(data_dict, u'id') try: jobs.job_from_id(id).delete() log.info(u'Cancelled background job {}'.format(id)) except KeyError: raise NotFound
def publishers_upload_status(task_id): """ Check status for the csv upload :param task_id: :return: """ result = {} job = jobs.job_from_id(id=task_id) if not job: raise ValidationError("No job associated with the given task id") result.update({'status': job.get_status()}) log.info(" csv check status info - job id: {}".format(task_id)) log.info(" csv check status info - job status: {}".format( job.get_status())) if job.result: result['result'] = {} try: data = json.loads(job.result) result['result']['added'] = data['added'] result['result']['updated'] = data['updated'] result['result']['errors'] = data['errors'] result['result']['warnings'] = data['warnings'] except Exception as e: result.update({'status': "failed"}) result['result'][ 'errors'] = "Something went wrong, while checking the job status." return json.dumps(result)
def get_celery_task_result(self): job = jobs.job_from_id(self.celery_task_id) result = job.result if result: return result else: raise TaskNotReady
def status(task_id=None): result = {} if task_id and task_id != 'undefined': try: job = jobs.job_from_id(id=task_id) result.update({'status': job.get_status()}) if job.result: result['result'] = {} try: result['result'].update(job.result[0]) result['result']['task_id'] = task_id except Exception as e: result.update({'status': "failed"}) result['result'] = {} result['result']['issue_type'] = "unknown error" result['result'][ 'issue_message'] = "Something went wrong, please try again or contact support." result['result']['task_id'] = task_id except Exception as e: result.update({'status': "failed"}) result['result'] = {} result['result']['issue_type'] = "unknown error" result['result'][ 'issue_message'] = "Something went wrong, please try again or contact support quoting the error \"Background job was not created\"" result['result']['task_id'] = task_id else: result.update({'status': 'failed'}) result['result'] = {} result['result']['issue_type'] = "unknown error" result['result'][ 'issue_message'] = "Something went wrong, please try again or contact support quoting the error \"Background job was not created\"" result['result']['task_id'] = task_id return json.dumps(result)
def check_status(self, task_id=None): result = {} if task_id: job = jobs.job_from_id(id=task_id) result.update({'status': job.get_status()}) if job.result: result['result'] = {} try: data = json.loads(job.result) result['result']['added'] = data['added'] result['result']['updated'] = data['updated'] result['result']['errors'] = data['errors'] result['result']['warnings'] = data['warnings'] except Exception as e: result.update({'status': "Something went wrong, please try again or contact support."}) print job.traceback else: result.update({'status': 'Invalid request.'}) return json.dumps(result)
def test_job_from_id_not_existing(self): with pytest.raises(KeyError): jobs.job_from_id(u"does-not-exist")
def test_job_from_id_existing(self): job = self.enqueue() assert jobs.job_from_id(job.id) == job job = self.enqueue(queue=u"my_queue") assert jobs.job_from_id(job.id) == job
def test_job_from_id_not_existing(self): jobs.job_from_id(u'does-not-exist')
def test_job_from_id_existing(self): job = self.enqueue() assert_equal(jobs.job_from_id(job.id), job) job = self.enqueue(queue=u'my_queue') assert_equal(jobs.job_from_id(job.id), job)