Skip to main content

Programmatic time-based job scheduler

Project description

🔮 Crono

Crono is a programmatic time-based job scheduler that gives your application a sense of timing.

import crono
crono.request('GET', 'https://www.google.com/').after(minutes=15)

Read more

Install

Install the library:

pip install crono

Run the servers:

redis-server &
celery worker --app=crono.queue:queue --hostname=worker1@%h
celery beat --app=crono.queue:queue

Usage

Triggers

A trigger defines when a job will be executed. There are 4 types of triggers: after, on, every, and cron.

after

after specifies a countdown until the execution of a task. It will only occur once. It takes at least 1 keyword argument: hours, minutes, and/or seconds, of type . Those keywords arguments are cumulative (same for the every trigger). For example, hours=1, minutes=30 equals minutes=90.

crono.after(minutes=30).

on

on specifies the execution of a task at a specific date and time. It will only occur once. It takes 1 positional argument of type <datetime.datetime>.

import datetime
date = datetime.datetime(2019, 7, 4)
crono.on(date).

every

every specifies a frequency at which to execute a task. It will occur multiple times. It takes at least 1 keyword argument: hours, minutes, and/or seconds, of type . Those keywords arguments are cumulative (similarly to the after trigger). For example, hours=1, minutes=30 equals minutes=90.

crono.every(hours=1, minutes=30).

cron

cron uses an expression to specify the execution time. It will occur mutiple times. It takes exactly 1 positional argument of type <str>.

crono.cron('0 6 * * 2').

Tasks

A task defines what a job will do. There are 4 types of tasks: log, request, message, and email.

log

log uses the standard logging Python library.

crono.log('DEBUG', '{text}', *args, **kwargs)

request

request sends an HTTP request. It is powered by the Requests library.

crono.request('POST', '{url}', **kwargs).

message

message sends an SMS. It is powered by Twilio. To use it, you will have to specify twilio_account_sid and twilio_auth_id.

Not implemented, yet.

email

email sends an email. It is powered by Postmark. To use it, you will have to specify postmark_api_key and postmark_sender.

Not implemented, yet.

Examples

import crono

# Timer
crono.request('POST', '{url}').after(minutes=1)

# Datetime
crono.log('DEBUG', '{text}').on(<datetime>)

# Interval
crono.email().every(hours=1) # `email` task not implemented (yet)

# Cron
crono.message().cron('0 6 * * 2') # `message` task not implemented (yet)

Configuration

Crono comes with sensible default values that you can override:

REDIS_MAX_CONNECTIONS (default: 20)	
CELERY_BROKER
CELERY_RESULT_BACKEND
CELERY_BROKER_POOL_LIMIT (default: 0)
CELERY_TASK_IGNORE_RESULT (default: True)
CELERY_BEAT_MAX_LOOP_INTERVAL (default: 300)
CELERY_WORKER_MAX_TASKS_PER_CHILD (default: 100)

Test

python -m pytest
celery flower -app=crono.queue:queue --address=127.0.0.1 --port=5555 --broker=redis://localhost:6379/0

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

crono-0.1.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

crono-0.1.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file crono-0.1.2.tar.gz.

File metadata

  • Download URL: crono-0.1.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.44.0 CPython/3.7.3

File hashes

Hashes for crono-0.1.2.tar.gz
Algorithm Hash digest
SHA256 cf0607a03e9b356055e24d8103390e54bfe72af6cb4cd63fd205b9ce27ec8b00
MD5 7ae5eb3687a2aaacb6cb0d3ff3042d20
BLAKE2b-256 c70cb4f27e0a7893529cc6586b7761cc1c9f82573cf82aab815f9064adaf5369

See more details on using hashes here.

File details

Details for the file crono-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: crono-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.44.0 CPython/3.7.3

File hashes

Hashes for crono-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 610b1775b40314b10f07405690c8c44c5c2f50b1ef1cfb7f2600d5f6ddc0ca1b
MD5 2e75c0eb84bbbce29ae82e635cd4180e
BLAKE2b-256 468b34709d2db701194d47186ce0ffdaff1c0943cc63bfd0232c617926d626b7

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