Skip to main content

a small cron-like scheduler in Python

Project description

fooster-cron

fooster-cron is small cron-like scheduler designed for simple, recurring jobs. It supports a basic set of field values though is extensible by using any class inheriting from cron.Field. Because this package is multiprocessing, shared objects must be synchronized, e.g. by multiprocessing.Manager.

Usage

Below is basic usage for calling a function and printing a message every hour (at minute 0), a set of minutes every hour, and every 20 minutes per hour.

from fooster import cron

def count():
    for i in range(5):
        print(i)

scheduler = cron.Scheduler()
scheduler.add(cron.Job(count, minute=5))
scheduler.add(cron.Job(print, ['Hourly function, run every hour on the hour!'], name='hourly', minute=0))
scheduler.add(cron.Job(print, ['This one runs at special minutes!'], minute=[1, 2, 3, 5, 8, 13, 21, 34, 55]))
scheduler.add(cron.Job(print, ['This one runs every 20 minutes within each hour!'], minute=cron.Every(20)))
scheduler.start()

scheduler.join()

cron.Job

Prototype:

cron.Job(function, args=(), kwargs={}, name=None, minute=cron.All(), hour=cron.All(), day=cron.All(), month=cron.All(), weekday=cron.All())

Attributes:

Attribute Value
function function to call
args tuple of function arguments
kwargs dictionary of named function arguments
minute range [0, 59]
hour range [0, 23]
day range [1, 31]
month range [1, 12]
weekday range [0, 6], 0 is Monday

cron.Field

To make a custom field, inherit from cron.Field and change the __eq__ method to return True when the passed value matches. The param member of the class is automatically populated with the passed argument unless the __init__ method is overridden. The value passed is a value from one of the time.struct_time fields.

Examples

List
class List(cron.Field):
    def __eq__(self, value):
        return value in self.param
All
class All(cron.Field):
    def __init__(self):
        pass

    def __eq__(self, value):
        return True

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

fooster-cron-0.9.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

fooster_cron-0.9.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file fooster-cron-0.9.0.tar.gz.

File metadata

  • Download URL: fooster-cron-0.9.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.9.0

File hashes

Hashes for fooster-cron-0.9.0.tar.gz
Algorithm Hash digest
SHA256 4829f942425d718a711de34e2c8c458dde57487c864e18f4f25cded836cee6ec
MD5 dd9e00a60578848883456e4de27b92b1
BLAKE2b-256 44b76c35afda5043e2e298618319c9ed3ab1514e1c7d2d04f213b1c544ab0a61

See more details on using hashes here.

File details

Details for the file fooster_cron-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: fooster_cron-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.9.0

File hashes

Hashes for fooster_cron-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a47fe5a88938408781eaf2e652727c346dc8c466f8893c2804c96494a57811b9
MD5 163d82a785aab67a53ace6a21421ef46
BLAKE2b-256 c1fa9490895480224bee099203f58c7de91407e6001ddd66aae400a0b5efe49d

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