0

i am new to celery. i have some configuration in celeryconfig.py as follow:

from datetime import timedelta

BROKER_URL='redis://localhost:6379/0'
CELERY_RESULT_BACKEND="redis"
CELERY_REDIS_HOST="localhost"
CELERY_REDIS_PORT=6379
CELERY_REDIS_DB=0
CELERY_IMPORT=("mail")

CELERYBEAT_SCHEDULE={'runs-every-30-seconds' :
                        {
                                'task': 'mail.mail',
                                'schedule': timedelta(seconds=30),
                        },
                    }

i have scheduled that the job will run periodically in 30 seconds. now i want that the jobs should start on 29 aug at 4:00PM then how should i configure this??

Rohitashv Singhal
  • 4,517
  • 13
  • 57
  • 105

1 Answers1

1

You should use Cron instead of timedelta. The Celery documentation discusses this specifically, and provides some useful examples. See Crontab schedules

Here is an example from Celery:

from celery.schedules import crontab

CELERYBEAT_SCHEDULE = {
    # Executes every Monday morning at 7:30 A.M
    'every-monday-morning': {
        'task': 'tasks.add',
        'schedule': crontab(hour=7, minute=30, day_of_week=1),
        'args': (16, 16),
    },
}

To make this work for your condition, you will also need to specify the cron month_of_year parameter.

Peter Kirby
  • 1,915
  • 1
  • 16
  • 29
  • hey, i want that the job should start at a fix time and should repeat after every 30 secons – Rohitashv Singhal Aug 29 '12 at 05:23
  • Ah, I see what you are saying. Off the top of my head, I can't think of a simple way to do this using the CELERYBEAT_SCHEDULE setting. However, this can be accomplished by creating a custom beat schedule class. See 'Custom Scheduler Class' http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html and here is the actual beat scheduler class documentation http://docs.celeryproject.org/en/latest/internals/reference/celery.beat.html#celery.beat.PersistentScheduler You will probably want to create a task that adds a new entry into the schedule, where that entry will be the 30-sec task – Peter Kirby Aug 29 '12 at 13:49
  • hey for example i have a job which i want to start at 4:00 PM on 31-Aug-2012 and this job should run after every 15 minutes – Rohitashv Singhal Aug 30 '12 at 06:06