Tuesday, March 30, 2021

cron-like scheduling on IBM Cloud

cron-like scheduling

Some days ago I stumbled over my 2015 post "Bluemix: Simple cron-like service for my Python code". It is not just the name Bluemix which is dated. Since then, it has transformed into IBM Cloud Platform and has added serverless compute options like IBM Cloud Functions (OpenWhisk) and recently IBM Cloud Code Engine. Both of them support "eventing", event-based execution of code. And both support Python code as well as many other programming languages like Node.js, Go (Golang), PHP and more. So, what does it take to set up cron-like scheduling? Not much.


The utility cron is a time-based scheduler for tasks (jobs) on UNIX / Linux systems. Events are specified by providing a set of values for minute, hour, day of the month, month, and day of the week. Values are either an explicit number, a comma-separated list of numbers, or the wildcard "*".

07 4,8,13,17 * * 1,3,5

The above would cause an event at 7 minutes past the hour at 4 am, 8 am, 1 pm and 5 pm, i.e., at 04:07, 08:07, 13:07 and 17:07. The event would only happen on Mondays (1), Wednesdays (3) and Fridays (5).

Alarms and pings

Cloud Functions has an integrated alarm package. It allows to set up time-based triggers. Based on rules, they can trigger actions. Here is a tutorial with a Python example used for daily collection of data.

Code Engine features a ping subscription as event producer. A ping subscription is directly associated with an app and a path. I utilize this feature for the daily collection of GitHub traffic statistics or to send out tweets.

You can of course use the eventing functionality to invoke a wrapper action or app / job which calls out into webhooks, invokes another function to perform database tasks or more.


Since my early tests with Python scheduling it has become much, much simpler to set up cron-like scheduling. IBM Cloud offers Cloud Functions and Code Engine as serverless compute options, each of them with eventing functionality. Both support the standard cron syntax for time events and allow to execute your tasks directly or use them as wrapper for something different.

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.