Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. @shared_task
  2. def post_notification(data,url):
  3. url = "http://posttestserver.com/data/?dir=praful" # when in production, remove this line.
  4. headers = {'content-type': 'application/json'}
  5. requests.post(url, data=json.dumps(data), headers=headers)
  6.  
  7.  
  8. @shared_task
  9. def shipment_server(data,notification_type):
  10. notification_obj = Notification.objects.get(name = notification_type)
  11. server_list = ServerNotificationMapping.objects.filter(notification_name=notification_obj)
  12.  
  13. for server in server_list:
  14. task = post_notification.delay(data,server.server_id.url)
  15. print task.status # it prints 'Nonetype' has no attribute id
  16.  
  17. for server in server_list:
  18. task = group(post_notification.s(data, server.server_id.url))().get()
  19. print task.status
  20.  
  21. TxIsolationWarning: Polling results w│
  22. ith transaction isolation level repeatable-read within the same transacti│
  23. on may give outdated results. Be sure to commit the transaction for each │
  24. poll iteration. │
  25. 'Polling results with transaction isolation level '
  26.  
  27. celery.current_app.send_task('mymodel.tasks.mytask', args=[arg1, arg2, arg3])
  28.  
  29. from app.tasks import celery_add_task
  30. celery_add_task.apply_async(args=[task_name])
  31.  
  32. from celery import group
  33.  
  34. @shared_task
  35. def shipment_server(data,notification_type):
  36. notification_obj = Notification.objects.get(name = notification_type)
  37. server_list = ServerNotificationMapping.objects.filter(notification_name=notification_obj)
  38.  
  39.  
  40. tasks = [post_notification.s(data, server.server_id.url) for server in server_list]
  41. results = group(tasks)()
  42. print results.get() # results.status() what ever you want
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement