celery.schedules

    exception celery.schedules.ParseException

    Raised by crontab_parser when the input can’t be parsed.

    class celery.schedules.schedule(run_every=None, relative=False, nowfun=None, app=None)[源代码]

    Schedule for periodic task.

    • app None

    • human_seconds None[源代码]

    • is_due(last_run_at)

      Returns tuple of two items (is_due, next_time_to_check), where next time to check is in seconds.

      e.g.

      • (True, 20), means the task should be run now, and the next

        time to check is in 20 seconds.

      • (False, 12.3), means the task is not due, but that the scheduler should check again in 12.3 seconds.

      The next time to check is used to save energy/cpu cycles, it does not need to be accurate but will influence the precision of your schedule. You must also keep in mind the value of CELERYBEAT_MAX_LOOP_INTERVAL, which decides the maximum number of seconds the scheduler can sleep between re-checking the periodic task intervals. So if you have a task that changes schedule at runtime then your next_run_at check will decide how long it will take before a change to the schedule takes effect. The max loop interval takes precendence over the next check at value returned.

      Scheduler max interval variance

      The default max loop interval may vary for different schedulers. For the default scheduler the value is 5 minutes, but for e.g. the django-celery database scheduler the value is 5 seconds.

    • maybe_make_aware(dt)

    • now()[源代码]

    • remaining_estimate(last_run_at)

    • seconds None[源代码]

    • to_local(dt)

    • tz None[源代码]

    • utc_enabled None

    class celery.schedules.crontab(minute=’\, hour=’*‘, day_of_week=’*‘, day_of_month=’*‘, month_of_year=’*‘, nowfun=None, app=None*)[源代码]

    A crontab can be used as the run_every value of a PeriodicTask to add cron-like scheduling.

    Like a cron job, you can specify units of time of when you would like the task to execute. It is a reasonably complete implementation of cron’s features, so it should provide a fair degree of scheduling needs.

    You can specify a minute, an hour, a day of the week, a day of the month, and/or a month in the year in any of the following formats:

    • minute

      • A (list of) integers from 0-59 that represent the minutes of an hour of when execution should occur; or
      • A string representing a crontab pattern. This may get pretty advanced, like minute=’*/15’ (for every quarter) or minute=‘1,13,30-45,50-59/2’.
    • hour

      • A (list of) integers from 0-23 that represent the hours of a day of when execution should occur; or
      • A string representing a crontab pattern. This may get pretty advanced, like hour=’*/3’ (for every three hours) or hour=‘0,8-17/2’ (at midnight, and every two hours during office hours).
    • day_of_week

      • A (list of) integers from 0-6, where Sunday = 0 and Saturday = 6, that represent the days of a week that execution should occur.
    • day_of_month

      • A (list of) integers from 1-31 that represents the days of the month that execution should occur.
      • A string representing a crontab pattern. This may get pretty advanced, such as day_of_month=‘2-30/3’ (for every even numbered day) or day_of_month=‘1-7,15-21’ (for the first and third weeks of the month).
    • month_of_year

      • A (list of) integers from 1-12 that represents the months of the year during which execution can occur.
      • A string representing a crontab pattern. This may get pretty advanced, such as month_of_year=’*/3’ (for the first month of every quarter) or month_of_year=‘2-12/2’ (for every even numbered month).
    • nowfun

      Function returning the current date and time ().

    • app

    It is important to realize that any day on which execution should occur must be represented by entries in all three of the day and month attributes. For example, if day_of_week is 0 and day_of_month is every seventh day, only months that begin on Sunday and are also in the month_of_year attribute will have execution events. Or, day_of_week is 1 and day_of_month is ‘1-7,15-21’ means every first and third monday of every month present in month_of_year.

    • is_due(last_run_at)[源代码]

      Returns tuple of two items (is_due, next_time_to_run), where next time to run is in seconds.

      See for more information.

    • now()[源代码]

    • remaining_delta(last_run_at, tz=None, ffwd=<class ‘celery.utils.timeutils.ffwd’>)

    • remaining_estimate(last_run_at, ffwd=<class ‘celery.utils.timeutils.ffwd’>)

      Returns when the periodic task should run next as a timedelta.

    class celery.schedules.crontab_parser(max_=60, min_=0)[源代码]

    Parser for crontab expressions. Any expression of the form ‘groups’ (see BNF grammar below) is accepted and expanded to a set of numbers. These numbers represent the units of time that the crontab needs to run on:

    The parser is a general purpose one, useful for parsing hours, minutes and day_of_week expressions. Example usage:

    It can also parse day_of_month and month_of_year expressions if initialized with an minimum of 1. Example usage:

    The maximum possible expanded value returned is found by the formula:

    • exception ParseException

      Raised by crontab_parser when the input can’t be parsed.

    celery.schedules.maybe_schedule(s, relative=False, app=None)