A work in progress: whenjobs — another cron replacement

whenjobs (git repo) is a cron replacement. From the manual page …

Whenjobs is a powerful but simple replacement for cron. It lets you run jobs periodically like cron, but it also lets you trigger jobs to run when user-defined variables are set or change value.

Periodic jobs are written like this:

every 10 minutes :
  # Get the current load average.
  load=`awk '{print $1}' /proc/loadavg`
  whenjobs --set load $load --type float

When-statements let you create jobs that run based on variables set elsewhere:

when load >= 6 :
  mail -s "ALERT: high load average: $load" $LOGNAME < /dev/null

(When statements are "edge-triggered", meaning that this job will only run when the load goes from under 6 to ≥ 6).

The motivation is building things from git automatically. Here is another job script:

Every 10 minutes, get the latest tagged version from the git repository. The variable ‘version’ will be set to something like “v1.2.3”, “v1.2.4”, etc over time as new releases get tagged.

every 10 minutes :
  cd /my/git/repo
  tag=`git-describe --tags`
  whenjobs --set version $tag

When the ‘version’ variable changes (ie. a new release is tagged) try to build it. ‘changes’ is a function that compares the previous value of a variable from when this job last ran with the current value of a variable, and returns true if the previous and current values are different.

when changes version :
  cd /my/git/buildrepo
  git pull
  git reset --hard $version
  make clean all check dist
  whenjobs --set successful_local_build $version

In parallel, build on a remote machine.

when changes version :
  ssh remote ./do_build $version
  whenjobs --set successful_remote_build $version

Only when the new release has been successfully built on local and remote, upload it to the website.

when successful_local_build == version &&
     successful_remote_build == version :
  cd /my/git/buildrepo
  curl -T name-$success.tar.gz ftp://ftp.example.com/upload/


Filed under Uncategorized

4 responses to “A work in progress: whenjobs — another cron replacement

  1. Nice. I’d expect something integrated in systemd 😉

  2. IMO it would need “3rd Monday of the month”, holidays and maybe even “full moon” etc to be a really good replacement.

  3. Marc Schöchlin

    Hm nice, one feature-suggestion regarding clustered environments:
    – synchronize job-definitions description to every member of a cluster
    – workload management/high avilability jobs: execute a job only on one cluster member, prevent double execution
    – job synchonisations: define rules

  4. Pingback: Still looking for good workflow management | Richard WM Jones

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.