Skip to main content

A pythonic cron using asyncio

Project description

CoroCron

CoroCron is a cron like scheduler for python functions. It uses asyncio to asynchronously start jobs at the specified schedule. The jobs are then put on the event loop when the schedule specified is met.

Usage

You can find more usage examples in the examples directory

Step 1: Create the base cron object

import CoroCron
Cron = CoroCron.Cron()

Note: By default Cron uses the local timezone but it can be modified to use UTC by initializing like so: CoroCron.Cron(True)

Step 2: Add jobs

Cron.Job().Days().Hours().Minutes().Do(function, args)

Job options

  • Any option defaults to all of the given period
    • Like * in cron
    • e.g. .Days() would run every day in a given month
  • Otherwise a list can be specified for which days
    • Any iterable or single numeric (.Days(4)) can also be used.
    • e.g. .Hours([0,2,4]) would run at 12am, 2am, and 4am
  • Any period after the initial setting will default to the first if not specified
    • For days: 1st day of the month
    • For hours: 0th hour (12am)
    • For minutes: 0th minute
    • e.g. Cron.Job().Days().Do(something) = something will be done every day at 12:00am
    • e.g. Cron.Job().Months().Minutes([15,30]).Do(something) = something will be done the 1st day of the month at 12:15am and 12:30am
  • Periods
    • Months() - Months of the year
    • Days() - Days of the month
    • Weekdays() - Days of the week (note: you can either specify days XOR weekdays, not both)
      • Monday = 0, Sunday = 6. An enum is also provided: CoroCron.Weekdays
    • Hours() - Hours of the day
    • Minutes() - Minutes in the hour
  • Do(function, args=())
    • This is the coroutine that you want to execute when the time is right
    • The function should be passed by reference (i.e. without parenthesis at the end)
    • You can pass args as a tuple in the 2nd parameter

Step 3: Start the Cron

Cron.Start(blocking = False)

By default Start() returns a future which can be awaited in an async funtion or added to a loop with ensure_future. If you set blocking to True it will instead be a blocking call using loop.run_forever()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CoroCron-0.1.5.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file CoroCron-0.1.5.tar.gz.

File metadata

  • Download URL: CoroCron-0.1.5.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

File hashes

Hashes for CoroCron-0.1.5.tar.gz
Algorithm Hash digest
SHA256 1b5cbc2f82c3cc5e286e20986cfe6c5aae7df9e2152483b8c58f07a31dbda7a8
MD5 9fcb7e7f8733079a5e1ff2a478430fba
BLAKE2b-256 7aedfa095ac1b65a9c8f988852908f6e7aeaa4c2193409a7896928c161293e10

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page