Git Product home page Git Product logo

celery-routing-example's Introduction

This code shows how to route tasks to specific queues, it can be useful to prioritize tasks based on named queues.

Dependencies

This example requires at least Python 3.6 (for no other reason than the use of f-strings but still...) and Redis which is used by Celery to handle the tasks. If you don't have Redis installed you can you the provided docker-compose.yml to run it so you can keep your system clean.

Setting up the environment

  • Install the dependencies using the provided requirements.txt file
  • Run Redis

First example

For the first example we will have one worker listening to the low priority queue and another listening to the default queue, to see the results it would be ideal to have three terminals, two for the worker and one for the task_test.py script.

Run the low priority worker with: $ celery -A tasks worker --loglevel=INFO -Q low

Run the default priority worker with: $ celery -A tasks worker --loglevel=INFO -Q default

Run the test script with: $ python task_test.py

As you can see the low priority worker will be idle after it will finish to handle the low priority tasks, and this is not ideal.o


Second example

For the second example we will have to low priority worker listening to both queues so it will not be idle when it finished with the low priority tasks

Run the low,default priority worker with: $ celery -A tasks worker --loglevel=INFO -Q low,default

Run the default priority worker with: $ celery -A tasks worker --loglevel=INFO -Q default

Run the test script with: $ python task_test.py

In this case the first worker will continue to be busy when it will finish with the low priority tasks solving the idling worker problem

celery-routing-example's People

Contributors

fpischedda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.