Cron jobs handle a lot of background plumbing that keep applications running smoothly. But cron job failures often go unnoticed and be disastrous for your users and business. To make sure that you are aware about cron job issues, you should use a cron monitoring tool. In this post, we will see how to get started with Cronitor to monitor your cron jobs.
Create a new cron job monitor
Sign up for a new account on Cronitor and select Cron job from the Create Monitor screen.
To create a cron job monitor, you should add the cron job expression which tells Cronitor about when your cron job runs, and the timezone for the cron job. For example, “0 0 * * *” expression means that your cron job runs every midnight. You can create cron expressions with ease using Crontab guru.
Next, you should specify if you want to be alerted if your cron job runs for longer than usual. You can specify the maximum time for which Cronitor can wait for job completion before it sends an alert. This is useful when slow performing cron jobs can cause issues.
Sometimes, an individual cron job failures may not matter. In this case, you can choose to be alerted only if a cron job fails more than a certain number of times. Next, select a name for your new monitor and save.
Integrate Cronitor in your cron job
After creating a new monitor, you should integrate Cronitor in your cron job. Cronitor has SDKs for different languages like Python, node.js etc. You can also call the unique HTTP URLs in your cron job to tell Cronitor when your cron job starts, completes and fails.
Based on the cron job schedule that you configured for your monitor, Cronitor will be expecting pings from your cron job. You can now get alerted if a cron job fails to start, runs for too long or fails during execution.
Setting up alerts
To make sure that you are aware of cron job failures, it is important to set up alerts for you and your team members.
You can set up emails from Cronitor directly, or you can use Spike.sh to get cron failure alerts on phone call, SMS, Slack and Microsoft Teams. You can create an escalation policy so if a team member is not able to attend to an alert, it automatically calls the next team member in the schedule.
That’s it! We saw how easy it is to start monitoring your cron jobs and start getting alerts if anything goes wrong. If you would like to know about adding monitoring and alerts to your production stack, email us at [email protected].