Skip to main content

Cron with hooks (webhook and others)

Project description

hoocron

Hoocron is cron alternative with different hooks to trigger immediate execution of jobs

Installation

pip3 install hoocron

Usage examples

Simple cron

We will run program /bin/touch with different arguments.

Simplest case:

$ hoocron.py -j TICK echo ...tick-tock... -p TICK 10s
started cron thread with 1 jobs: TICK
run TICK from cron
...tick-tock...
Return code for TICK: 0

run TICK from cron
...tick-tock...
Return code for TICK: 0

This command configures job (what to run, command and arguments) and hook (when to run). This very similar to cron. Here we have job named 'J' which runs /bin/touch /tmp/touch and configured cron period (-p) for job J to 20 seconds.

We can run many jobs at once, lets add also 'echo'

$ hoocron.py -j Echo5 echo tick-tock 5 seconds -j Echo10 echo tick-tock 10 seconds -p Echo5 5 -p Echo10 10

### immediately, 0s from start
run Echo5 from cron
run Echo10 from cron
tick-tock 5 seconds
tick-tock 10 seconds
Return code for Echo5: 0
Return code for Echo10: 0

### 5s from start
run Echo5 from cron
tick-tock 5 seconds
Return code for Echo5: 0

### 10s from start
run Echo5 from cron
run Echo10 from cron
tick-tock 5 seconds
tick-tock 10 seconds
...

Webhook HTTP trigger

HTTP plugin provides HTTP GET and HTTP POST interface to start cron job right now.

Now, lets make it more interesting, we will also run job if get HTTP request using --http-get option (or just --get).

$ hoocron.py -j J /bin/touch /tmp/touch -p J 5m --get J
Loading hoocron_plugin.cron
Loading hoocron_plugin.http
Loading hoocron_plugin.redis
started cron thread with 1 jobs: J
started http thread on :5152 with 1 jobs: J
run J from cron
Return code for J: 0

Hoocron immediately runs Job (because cron plugin runs each job for first time right from start) and waits 5 minutes for next run. We do not want this, so we do:

$ curl http://localhost:5152/J
OK

This triggers hoocron execution of job J:

run J from HTTP GET request from 127.0.0.1
Return code for J: 0

Cron with HTTP POST method

If you want to use HTTP POST method, use --post (or --http-post alias) instead of --get.

Running hoocron with http in production

If you need extra HTTP features, such as https support or additional access control, run hoocron behind real webserver working as reverse proxy.

Throttling and policies

Hoocron guarantees that only one copy of job (with same job name) is running at same time (same jobs will not overlap): hoocron will never start second copy of same job until first one is finished.

But hoocron can not prevent same script started from any other source (e.g. from shell).

There are two policies for job, ignore (default) and asap.

With policy ignore, if hoocron gets request to start job, and this job is already running, request is ignored.

With policy asap, if hoocron gets request to start job, and this job is already running, it will set special flag and will run same job again immediately after first instance of job is finished (and again, new request will raise flag again). Note, if there are many requests during one execution of job, it will be executed just once.

To see difference, compare ignore policy (default) with this command:

hoocron.py -j J sleep 10 -p J 3

and same with asap policy

hoocron.py -j J sleep 10 -p J 3 --policy J asap

See also

Redis plugin

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

hoocron-0.0.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file hoocron-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: hoocron-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.3

File hashes

Hashes for hoocron-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aec1dc804a4868512b47cdcc256226f1db65ba242e621179ba4ec485a7f1787f
MD5 b9a1ea28ec86beb45a160781326edafb
BLAKE2b-256 7ba4c941cf9eb5c8a8165e76fa78c47c62d316f7d1e75a8644612209e2651337

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