本文整理汇总了Python中jobs.models.Job.get方法的典型用法代码示例。如果您正苦于以下问题:Python Job.get方法的具体用法?Python Job.get怎么用?Python Job.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jobs.models.Job
的用法示例。
在下文中一共展示了Job.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_job_work
# 需要导入模块: from jobs.models import Job [as 别名]
# 或者: from jobs.models.Job import get [as 别名]
def do_job_work(request):
init_jobs()
try:
job = Job.get(request.POST['job_key'])
params = request.POST.get('params', '{}')
worker = get_worker(job.job_name)
if worker['pre_request']:
early_response = worker['pre_request'](request)
if early_response is not None:
return early_response
if job.result:
result_for_worker = simplejson.loads(job.result)
else:
result_for_worker = None
finished, result = worker['callback'](result_for_worker,
simplejson.loads(params))
job.result = simplejson.dumps(result)
job.save()
except:
traceback.print_exc()
raise
@as_json
def data(request):
return {
'finished': finished,
'success': True
}
return data(request)
示例2: test_job_reaper_kills_old_jobs
# 需要导入模块: from jobs.models import Job [as 别名]
# 或者: from jobs.models.Job import get [as 别名]
def test_job_reaper_kills_old_jobs(self):
# make an old job:
job = Job(job_name='counter')
job.started = datetime.datetime.now() - timedelta(days=3)
job.save()
old_job_key = job.key()
response = self.client.post(reverse('jobs.start'), {
'job_name': 'counter'
})
json_response = simplejson.loads(response.content)
self.assert_json_success(json_response)
self.assertEqual(Job.get(old_job_key), None)
示例3: get_job_product
# 需要导入模块: from jobs.models import Job [as 别名]
# 或者: from jobs.models.Job import get [as 别名]
def get_job_product(request, job_key):
init_jobs()
job = Job.get(job_key)
if job is None:
raise Http404(
"The requested job product does not exist. It may have expired, "
"in which case you will have to run the job again.")
# TODO(kumar) make sure job is finished
producer = get_producer(job.job_name)
if producer['pre_request']:
early_response = producer['pre_request'](request)
if early_response is not None:
return early_response
result = simplejson.loads(job.result)
return producer['callback'](result)