Created
April 22, 2016 04:46
-
-
Save superdaigo/3a07123be09dc6fb8b3b902fc2e9b08e to your computer and use it in GitHub Desktop.
Celery rate_limit test script
This file contains hidden or 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
""" | |
# 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