Polling with the Cron Format (* * * * *)
Polling is a common technique in programming where you repeatedly check the status or result of a task or resource at regular intervals. One of the most common ways to schedule tasks for polling in Unix-like systems is using the cron format. This format defines when a command or script should be executed.
The cron format follows the structure * * * * *, which represents:
Minute (0-59)
Hour (0-23)
Day of the Month (1-31)
Month (1-12)
Day of the Week (0-7, where both 0 and 7 represent Sunday)
Each field can be filled with:
A specific value (e.g.,
5for 5th minute)A range of values (e.g.,
1-5for the 1st to 5th minute)A list of values (e.g.,
1,5,10for the 1st, 5th, and 10th minutes)An asterisk
*, which represents all possible values for that fieldA step value (e.g.,
*/5for every 5 minutes)
Some Examples
# Example 1: Polling Every Minute
H * * * *
# Use Case: Frequent polling, but the exact minute will be distributed to avoid server overload.
# Example 2: Polling Every 5 Minutes
H/5 * * * *
# Use Case: Polling every 5 minutes, but the starting minute will vary per build to distribute load.
# Example 3: Polling Every Hour at the 15th Minute
H(15) * * * *
# Use Case: Polling exactly at the 15th minute of every hour, distributed across builds.
# Example 4: Polling at Midnight Every Day
H 0 * * *
# Use Case: Daily midnight polling, but the exact minute will be hashed to avoid all jobs running at the same time.
# Example 5: Polling Every Monday at 8 AM
H 8 * * 1
# Use Case: Weekly polling every Monday at 8 AM, with minute distribution to spread the load.
# Example 6: Polling Every Last Day of the Month at 11:59 PM
H 23 28-31 * *
# Use Case: Month-end polling tasks distributed across the last days of the month at 11:59 PM.
# Example 7: Polling Every 15 Minutes Between 9 AM and 5 PM on Weekdays
H/15 9-17 * * 1-5
# Use Case: Polling every 15 minutes during working hours on weekdays, with load balanced across different builds.
# Example 8: Polling on the First Day of Every Month at 6 AM
H 6 1 * *
# Use Case: Monthly polling at 6 AM on the first day of each month, with load distribution.

