Skip to main content

A cron job runner with self-healing and job dependencies.

Project description

A cron job runner with self-healing and job dependencies.

License: MPL 2

Coverage Status

Build Status

How to run tests

First you need to create a dedicated test database. We recommend you call it test_crontabber. Then you need the necessary credentials for it.

Before running the tests you need to install some extras to be able to run tests at all:

pip install -r test-requirements.txt

Next, in the root directory of the project create a file called test-crontabber.ini and it should look something like this:

[crontabber]
user=myusername
password=mypassword
dbname=test_crontabber

To start all the tests run:

PYTHONPATH=. nosetests

If you want to run a specific test in a specific file in a specific class you can define it per the nosetests standard like this for example:

PYTHONPATH=. nosetests tests crontabber/tests/test_crontabber.py:TestCrontabber.test_basic_run_job

If you want the tests to stop as soon as the first test fails add -x to that same command above.

Also, if you want nosetests to not capture stdout add -s to that same command as above.

How to do code coverage analysis

First you need to install the coverage module. Then, with nosetests, you can run this:

PYTHONPATH=. nosetests --with-coverage --cover-erase --cover-html --cover-package=crontabber

After it has run, you can open the file cover/index.html in browser.

How to run the exampleapp

The example app helps you set up a playground to play around with and test crontabber to gain a better understanding of how it works.

The best place to start with is to read the exampleapp/README.md file and go through its steps. Once you get the basics to work you can start experimenting with adding your job classes.

How locking works

crontabber supports locking. It basically means if you start a second instance of crontabber whilst it’s already ongoing in another terminal/server the second one will exist early. This is only applicable if there is an actual job ongoing.

There are two kinds of locking.

  1. General locking. The first thing crontabber does before it starts an app is to ask the state (stored in PostgreSQL) if it’s ongoing and if it is, it exists with an error code of 3.

  2. Sub-second locking. If the general locking (see point above) says “No, the job is not ongoing”, it’s going to proceed to update the state with a row-level locking transaction in PostgreSQL. That basically means PostgreSQL only allows one single UPDATE from the process that gets there first. The second crontabber process will will exit early with an error code of 2 if the first crontabber process managed to run the UPDATE first.

Imagine two separate terminals starting crontabber at the almost same time:

# Terminal 1
$ python crontabber.py --admin.conf=crontabber.ini
$ echo $?
0
# Terminal 2 (started almost simultaneously)
$ python crontabber.py --admin.conf=crontabber.ini
$ echo $?
3

Note! If a job has been ongoing to a maximum period of time, the locking is ignored. This is controlled by the config option crontabber.max_ongoing_age_hours which defaults to 12 hours. This is applicable if crontabber, updates the state that it’s starting a job, then when it tries to update the state that it finished (successfully or not) and that write fails, if for example it’s unable to make a connection to PostgreSQL. If this happens crontabber will just ignore the lock and run it anyway.

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

crontabber-0.18.1.tar.gz (51.3 kB view details)

Uploaded Source

Built Distribution

crontabber-0.18.1-py2-none-any.whl (55.4 kB view details)

Uploaded Python 2

File details

Details for the file crontabber-0.18.1.tar.gz.

File metadata

  • Download URL: crontabber-0.18.1.tar.gz
  • Upload date:
  • Size: 51.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for crontabber-0.18.1.tar.gz
Algorithm Hash digest
SHA256 dfe4086a23928647bb021ba0a8bf3e7bb9e86792042506dcca5040061b310d3e
MD5 f13bd8aa33018e7ccb9fe1f29a30e5d6
BLAKE2b-256 b854643a25075bb9ceee2854c5ba723618d13e01142afb18e31039d776b192d2

See more details on using hashes here.

File details

Details for the file crontabber-0.18.1-py2-none-any.whl.

File metadata

File hashes

Hashes for crontabber-0.18.1-py2-none-any.whl
Algorithm Hash digest
SHA256 da4b6d06b4955ed3439a3d5ccc09cb1b3fa644d11d6222c55611c1c64be5323d
MD5 cf1729aec1085a7d818d9cff490e4693
BLAKE2b-256 f0802e63b47598a5458ccc4c212dea727f3511399f2af4b00660e4f92da580fb

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