messaging.py 729 B

12345678910111213141516171819202122232425262728
  1. from carrot.messaging import Publisher, Consumer
  2. import uuid
  3. class NoProcessConsumer(Consumer):
  4. def receive(self, message_data, message):
  5. raise NotImplementedError(
  6. "Don't use process_next() or wait() with the TaskConsumer!")
  7. class TaskPublisher(Publisher):
  8. exchange = "crunchy"
  9. routing_key = "crunchy"
  10. def delay_task(self, task_name, **kwargs):
  11. task_id = uuid.uuid4()
  12. message_data = dict(kwargs)
  13. message_data["crunchTASK"] = task_name
  14. message_data["crunchID"] = str(task_id)
  15. self.send(message_data)
  16. return task_id
  17. class TaskConsumer(NoProcessConsumer):
  18. queue = "crunchy"
  19. exchange = "crunchy"
  20. routing_key = "crunchy"