Giter VIP home page Giter VIP logo

parse-crontab's Introduction

Copyright 2011-2016 Josiah Carlson

Released under the LGPL license version 2.1 and version 3 (you can choose which you'd like to be bound under).

Description

This package intends to offer a method of parsing crontab schedule entries and determining when an item should next be run. More specifically, it calculates a delay in seconds from when the .next() method is called to when the item should next be executed.

Comparing the below chart to http://en.wikipedia.org/wiki/Cron#CRON_expression you will note that W and # symbols are not supported.

Field Name Mandatory Allowed Values Allowed Special Characters
Minutes Yes 0-59 * / , -
Hours Yes 0-23 * / , -
Day of month Yes 1-31 * / , - ? L
Month Yes 1-12 or JAN-DEC * / , -
Day of week Yes 0-6 or SUN-SAT * / , - ? L
Year No 1970-2099 * / , -

Sample individual crontab fields

Examples of supported entries are as follows:

*
*/5
7/8
3-25/7
3,7,9
0-10,30-40/5

For month or day of week entries, 3 letter abbreviations of the month or day can be used to the left of any optional / where a number could be used.

For days of the week:

mon-fri
sun-thu/2

For month:

apr-jul
mar-sep/3

Example uses

>>> from crontab import CronTab
>>> from datetime import datetime
>>> # define the crontab for 25 minutes past the hour every hour
... entry = CronTab('25 * * * *')
>>> # find the delay from when this was run (around 11:13AM)
... entry.next()
720.81637899999998
>>> # find the delay from when it was last scheduled
... entry.next(datetime(2011, 7, 17, 11, 25))
3600.0

Notes

At most one of 'day of week' or 'day of month' can be a value other than '?' or '*'. We violate spec here and allow '*' to be an alias for '?', in the case where one of those values is specified (seeing as some platforms don't support '?').

This module also supports the convenient aliases:

@yearly
@annually
@monthly
@weekly
@daily
@hourly

Example full crontab entries and their meanings:

30 */2 * * * -> 30 minutes past the hour every 2 hours
15,45 23 * * * -> 11:15PM and 11:45PM every day
0 1 ? * SUN -> 1AM every Sunday
0 1 * * SUN -> 1AM every Sunday (same as above)
0 0 1 jan/2 * 2011-2013 ->
    midnight on January 1, 2011 and the first of every odd month until
    the end of 2013
24 7 L * * -> 7:24 AM on the last day of every month
24 7 * * L5 -> 7:24 AM on the last friday of every month
24 7 * * Lwed-fri ->
    7:24 AM on the last wednesday, thursday, and friday of every month

parse-crontab's People

Contributors

josiahcarlson avatar grahambell avatar jayvdb avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.