Run Jobs Every Two Hours on the Hour | CronBase

cron expression Standard
$ 0 */2 * * *

Every two hours on the hour.

The `0 */2 * * *` cron expression executes a task every two hours at the start of the hour (minute zero). It triggers at midnight, 2:00 AM, 4:00 AM, and so forth throughout the day, providing a consistent bi-hourly cadence ideal for high-frequency maintenance and continuous data processing pipelines.

Minute
0
Hour
*/2
Day of Month
*
Month
*
Day of Week
*

Next 5 Runs

  • in 3m 18s
  • in 2h 3m
  • in 4h 3m
  • in 6h 3m
  • in 8h 3m

* Tools

Code & Implementations

nodejs
const cron = require('node-cron');

// Schedule task to run every two hours: 0 */2 * * *
cron.schedule('0 */2 * * *', async () => {
    const startTime = new Date().toISOString();
    console.log(`[${startTime}] Starting bi-hourly cache invalidation...`);
    try {
        await performCacheClean();
        console.log(`[${new Date().toISOString()}] Cache invalidation completed successfully.`);
    } catch (error) {
        console.error(`[${new Date().toISOString()}] Critical error during cache invalidation:`, error.message);
        // In production, integrate with Sentry, PagerDuty, or Datadog here
    }
}, {
    scheduled: true,
    timezone: "Etc/UTC"
});

async function performCacheClean() {
    return new Promise((resolve) => setTimeout(resolve, 5000));
}
Setup notes

Install the dependency using npm install node-cron and run this script as a background daemon process using PM2 or Docker.

Partner BetterStack

Monitor this schedule in production

Get alerted the moment this cron job fails, is late, or doesn't run. BetterStack tracks execution, duration, and output — no infrastructure required.

Platform Equivalents

AWS EventBridge

Standard cron expressions often need conversion for AWS EventBridge schedules.

EventBridge Rule
cron(0 */2 * * ? *)

Systemd Timer

OnCalendar*-*-* 00/2:00:00

my-task.timer
[Unit]
Description=Timer for cron expression: 0 */2 * * *

[Timer]
OnCalendar=*-*-* 00/2:00:00
Persistent=true

[Install]
WantedBy=timers.target

Frequently Asked Questions

How do I prevent overlapping runs if a job takes longer than two hours?

Implement a locking mechanism. In Kubernetes, set `concurrencyPolicy: Forbid`. On Linux servers, wrap your script in a utility like `flock` or utilize distributed lock managers like Redis (Redlock) or Consul to ensure only one instance runs at any given time.

What is the best way to handle Daylight Saving Time changes with this schedule?

Configure your system clock, cron daemon, or container runtime to use Coordinated Universal Time (UTC). Operating on UTC guarantees that the job executes consistently every 120 minutes without skipping or running twice during seasonal clock adjustments.

How does 0 */2 * * * differ from matching every minute like */120 * * * *?

Standard cron engines do not support step intervals larger than 59 in the minutes field. Therefore, `*/120` is invalid. The expression `0 */2 * * *` specifies execution specifically at minute zero of every second hour (e.g., 12:00, 2:00, 4:00).

How can I spread the load if multiple cron tasks run at the same time?

Avoid scheduling all tasks at minute `0`. Shift the execution minute to an arbitrary value (for example, `17 */2 * * *` or `43 */2 * * *`). This distributes network, memory, and CPU utilization across your server infrastructure.

How should I monitor this cron job to ensure it runs successfully?

Use a passive monitoring tool or 'dead man's snitch' that expects an HTTP ping every two hours. Configure a grace period of 2.5 hours. If the service fails to ping within that window, trigger an alert via PagerDuty, Slack, or email.

* Explore

Related expressions you might need

Was this helpful?

Last verified: