本文整理匯總了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)