cool tech graphics

Celery Periodic Tasks: From Installation to Infinity

Filed under:

This is a quick example of how I got Periodic Tasks to work using Celery without Django. There are lots of examples out there for creating tasks and loose documentation on how to start Celery and Celery Beat, but most of them involve Django. I just wanted to run a simple example and I spent way too long trying to fill in the gaps to get even this simple task to run periodically. So hopefully this quick example will help somebody else out there save some time.


Installing Celery

sudo pip install Celery
You'll want to choose your broker; RabbitMQ is what comes recommended by default.

Create a

Once you install your broker of choice you can setup the configuration options in In my case I was using MySQL. Here is an example of what my file looked like.

# Change this to your settings
BROKER_URL = 'sqla+mysql://user:password@localhost/database'
CELERY_RESULT_DBURI = 'mysql://user:password@localhost/database'

Create some tasks

Create your tasks (generally they will be saved into a file called This is what my looks like:

from celery import Celery

celery = Celery('tasks')

def add(x, y):
return x + y

Update your

Now in order for Celery to know how often you want to run your periodic tasks, update your to add the following.

from celery.schedules import crontab

'every-minute': {
'task': 'tasks.add',
'schedule': crontab(minute='*/1'),
'args': (1,2),

Start Celery

Now we just need to start a Celery worker with the --beat flag and our task will run every minute. This part was not so obvious, but the --beat flag needs to appear after worker, otherwise nothing will happen.

$ celery -A tasks worker --loglevel=info --beat

Wait a minute...

You should see Celery output a bunch of info as tasks are ran. Among them you should see a line that looks like this:

[2012-12-07 13:26:00,343: INFO/MainProcess] Task tasks.add[44477955-906c-4827-bda2-f6f19822c652] succeeded in 0.00760388374329s: 3
Date posted: January 16, 2013


I was needing exactly this, and I 'm using Flask. I was doing a very simple test, an implementation, and I spent the past 4 hours trying to understand why it wasn't working at all !!. Thanks a lot !

I was searcing for the same kind of tutorial. Helped me a lot.

Hey Jonathan,

Thanks so much for your post. Simple and very helpful!

Soo Ling

Was running a separate process for beats, didn't realise I could just do "--beat". Cheers

thanks for your help

Awesome tutorial dude! Quick question though, how do I get the RESULT of my scheduled task out of celery.

Previously I'd been sending tasks to celery using the '.delay()' function. Lets say I had a task called "add" in my file.

I'd do:

from tasks import add
result = add.delay(6,7)

how do I get beats to tell me what the result of it's periodic task is?

Can I run beat periodic task scheduler with the -c:
celery worker -Q celery --beat -l info -c 4

Very helpful man thanks a lot!

In the below given code, what is "every-minute" means? we are mentioning 'crontab(minute='*/1')' to run the task for every 1 minute(If not , please correct me). So what is the use of 'every-minute' then ?

'every-minute': {
'task': 'tasks.add',
'schedule': crontab(minute='*/1'),
'args': (1,2),

every-minute is just an title for the scheduled task

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>, <java>, <php>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Metal Toad is an Advanced AWS Consulting Partner. Learn more about our AWS Managed Services

Have questions?