Skip to content

Instantly share code, notes, and snippets.

@superdaigo
Created April 22, 2016 04:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superdaigo/3a07123be09dc6fb8b3b902fc2e9b08e to your computer and use it in GitHub Desktop.
Save superdaigo/3a07123be09dc6fb8b3b902fc2e9b08e to your computer and use it in GitHub Desktop.
Celery rate_limit test script
"""
# Test celery's rate_limit
Tested version of python
$ python --version
Python 2.7.11
## Requirements
$ pip install celery==3.1.23
$ pip install SQLAlchemy==1.0.12
## Launch 5 celery workers
$ celery -A tasks worker -c 5 --loglevel=info
("-c" option specifies a number of celery worker)
## Add task
$ python
>>> import tasks
>>> for i in range(1, 10):
>>> tasks.hey.delay(i)
... see celery worker log ...
## Stop worker
Ctrl-c
"""
from celery import Celery
from datetime import datetime
app = Celery('tasks', broker='sqla+sqlite:///celery.db')
@app.task(rate_limit='30/m')
def hey(i):
return 'Hey! {0}'.format(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment