Skip to content

Instantly share code, notes, and snippets.

@Artimi
Last active May 16, 2023 10:49
Show Gist options
  • Save Artimi/97375451f298b9e8c745 to your computer and use it in GitHub Desktop.
Save Artimi/97375451f298b9e8c745 to your computer and use it in GitHub Desktop.
Dynamic queues in Celery
CELERY_IMPORTS = ('tasks')
CELERY_IGNORE_RESULT = True
CELERY_RESULT_BACKEND = 'amqp'
CELERYD_PREFETCH_MULTIPLIER = 1
import tasks
def send_requests(count, snd=0, queue='def'):
for i in range(count):
tasks.add.apply_async(args=(i, snd), queue=queue)
tasks.app.control.add_consumer('foo', reply=True)
tasks.app.control.add_consumer('bar', reply=True)
send_requests(30, 0, 'foo')
send_requests(10, 100, 'bar')
from __future__ import absolute_import
from celery import Celery
import celeryconfig
import time
app = Celery()
app.config_from_object(celeryconfig)
@app.task()
def add(x, y):
time.sleep(0.3)
return x + y
if __name__ == '__main__':
app.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment