本文整理汇总了Python中celery.task.TaskSet.apply_async方法的典型用法代码示例。如果您正苦于以下问题:Python TaskSet.apply_async方法的具体用法?Python TaskSet.apply_async怎么用?Python TaskSet.apply_async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.task.TaskSet
的用法示例。
在下文中一共展示了TaskSet.apply_async方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hotspotsRange_ts
# 需要导入模块: from celery.task import TaskSet [as 别名]
# 或者: from celery.task.TaskSet import apply_async [as 别名]
def hotspotsRange_ts(start_time, stop_time, location, **kwargs):
''' Run ofver a range of timesteps at 5 minute intervals in between '''
start = datetime.strptime(start_time, '%Y%m%d.%H%M%S')
stop = datetime.strptime(stop_time, '%Y%m%d.%H%M%S')
kwargs.update({'task_id': hotspotsRange.request.id})
job = TaskSet(tasks=[ cybercomq.gis.hotspotpysal.hotspots.subtask(args=(ts,location), kwargs=kwargs, queue="gis", track_started=True) for ts in date_range(start,stop) ])
job.apply_async(job)
return '%s' % (hotspotsRange_ts.request.id)
示例2: test_counter_taskset
# 需要导入模块: from celery.task import TaskSet [as 别名]
# 或者: from celery.task.TaskSet import apply_async [as 别名]
def test_counter_taskset(self):
increment_counter.count = 0
ts = TaskSet(tasks=[
increment_counter.s(),
increment_counter.s(increment_by=2),
increment_counter.s(increment_by=3),
increment_counter.s(increment_by=4),
increment_counter.s(increment_by=5),
increment_counter.s(increment_by=6),
increment_counter.s(increment_by=7),
increment_counter.s(increment_by=8),
increment_counter.s(increment_by=9),
])
self.assertEqual(ts.total, 9)
consumer = increment_counter.get_consumer()
consumer.purge()
consumer.close()
taskset_res = ts.apply_async()
subtasks = taskset_res.subtasks
taskset_id = taskset_res.taskset_id
consumer = increment_counter.get_consumer()
for subtask in subtasks:
m = consumer.queues[0].get().payload
self.assertDictContainsSubset({'taskset': taskset_id,
'task': increment_counter.name,
'id': subtask.id}, m)
increment_counter(
increment_by=m.get('kwargs', {}).get('increment_by'))
self.assertEqual(increment_counter.count, sum(xrange(1, 10)))
示例3: handle
# 需要导入模块: from celery.task import TaskSet [as 别名]
# 或者: from celery.task.TaskSet import apply_async [as 别名]
def handle(self, *args, **options):
docs = RECAPDocument.objects.exclude(filepath_local='')
if options['skip_ocr']:
# Focus on the items that we don't know if they need OCR.
docs = docs.filter(ocr_status=None)
else:
# We're doing OCR. Only work with those items that require it.
docs = docs.filter(ocr_status=RECAPDocument.OCR_NEEDED)
count = docs.count()
print("There are %s documents to process." % count)
if options.get('order') is not None:
if options['order'] == 'small-first':
docs = docs.order_by('page_count')
elif options['order'] == 'big-first':
docs = docs.order_by('-page_count')
subtasks = []
completed = 0
for pk in docs.values_list('pk', flat=True):
# Send the items off for processing.
last_item = (count == completed)
subtasks.append(extract_recap_pdf.subtask(
(pk, options['skip_ocr']),
priority=5,
queue=options['queue']
))
# Every enqueue_length items, send the subtasks to Celery.
if (len(subtasks) >= options['queue_length']) or last_item:
msg = ("Sent %s subtasks to celery. We have sent %s "
"items so far." % (len(subtasks), completed + 1))
logger.info(msg)
print(msg)
job = TaskSet(tasks=subtasks)
job.apply_async().join()
subtasks = []
completed += 1
示例4: make_download_tasks
# 需要导入模块: from celery.task import TaskSet [as 别名]
# 或者: from celery.task.TaskSet import apply_async [as 别名]
def make_download_tasks(data, line_count, start_line):
"""For every item in the CSV, send it to Celery for processing"""
previous_casenum = None
subtasks = []
completed = 0
for index, item in data.iterrows():
if completed < start_line - 1:
# Skip ahead if start_lines is provided.
completed += 1
continue
last_item = (line_count == completed + 1)
if item['casenum'] != previous_casenum:
# New case, get the docket before getting the pdf
logger.info("New docket found with casenum: %s" % item['casenum'])
previous_casenum = item['casenum']
filename = get_docket_filename(item['court'], item['casenum'])
url = get_docketxml_url(item['court'], item['casenum'])
subtasks.append(download_recap_item.subtask((url, filename)))
# Get the document
filename = get_document_filename(item['court'], item['casenum'],
item['docnum'], item['subdocnum'])
url = get_pdf_url(item['court'], item['casenum'], filename)
subtasks.append(download_recap_item.subtask((url, filename)))
# Every n items send the subtasks to Celery.
if (len(subtasks) >= 1000) or last_item:
msg = ("Sent %s subtasks to celery. We have processed %s "
"rows so far." % (len(subtasks), completed + 1))
logger.info(msg)
print msg
job = TaskSet(tasks=subtasks)
job.apply_async().join()
subtasks = []
completed += 1
示例5: test_function_taskset
# 需要导入模块: from celery.task import TaskSet [as 别名]
# 或者: from celery.task.TaskSet import apply_async [as 别名]
def test_function_taskset(self):
subtasks = [return_True_task.s(i) for i in range(1, 6)]
ts = TaskSet(subtasks)
res = ts.apply_async()
self.assertListEqual(res.join(), [True, True, True, True, True])