def start_celery_task(request): task = long_task.delay() if(task): task = AsyncResult(task.id) data = task.result or task.state return HttpResponse(json.dumps(data), content_type= 'applicatoin/json') else: task = long_task.delay() #return render_to_response('start.html', { #'task_id': task.id}) #return HttpResponseRedirect("%s%s" % ('/celery_porgress?task_id=', task.id)) ##def monitor_celery_ask(request): #if 'task_id' in request.GET: #task_id = request.GET['task_id'] #else: #return HttpResponse('No task id passed') #task = AsyncResult(task_id) #data = task.result or task.state #return render_to_response('work.html', #{'data': data}) ##return HttpResponse(data)
def searche(): print(request.args.get('name')) keyname = request.args.get('name') if keyname == '': return '<h2>空值查询什么呢...</h2>' try: certen_nub = int(request.args.get('c')) except: certen_nub = None print("certen_nub=", certen_nub) if certen_nub is not None: task = long_task.delay(keyname) return '<h2>后台已经再执行程序了,请20分钟以后查看...</h2>' km = KeywordsMongo() qname_list = km.get_collections_names() if len(qname_list) == 0: # kspider = keywordsspider.KeywordsSpider(keyname) # return_context = kspider.get_urls_from_baidu() task = long_task.delay(keyname) return '<h2>后台已经再执行程序了,请20分钟以后查看...</h2>' if (keyname in qname_list): results = km.get_info_by_collection_name(keyname) return_context = [] for result in results: return_context.append(result) return render_template('exist_data.html', context=return_context) else: task = long_task.delay(keyname) return '<h2>后台已经再执行程序了,请20分钟以后查看...</h2>'
from tasks import long_task if __name__ == '__main__': x = long_task.delay(5) print('end of main script') z = x.get() print(z)
import time from tasks import app, add, xsum, long_task if __name__ == '__main__': reply = app.control.broadcast('rate_limit', { 'task_name': 'tasks.add', 'rate_limit': '10/m' }, reply=True) print('Reply: %s' % reply) # revoke a task result = long_task.delay() time.sleep(3) # below is equal to: result.revoke() app.control.revoke(result.task_id, terminate=True) # time limit don’t currently work on platforms that don’t support the SIGUSR1 signal. # so it cannot work on Windows. reply = app.control.time_limit('tasks.long_task', soft=10, hard=20, reply=True) print('Reply: %s' % reply) long_task.apply_async() # add consumer reply = app.control.add_consumer( queue='baz', exchange='ex', exchange_type='topic',