Last active
May 16, 2023 10:49
-
-
Save Artimi/97375451f298b9e8c745 to your computer and use it in GitHub Desktop.
Dynamic queues in Celery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CELERY_IMPORTS = ('tasks') | |
CELERY_IGNORE_RESULT = True | |
CELERY_RESULT_BACKEND = 'amqp' | |
CELERYD_PREFETCH_MULTIPLIER = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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