DevToolBoxKOSTENLOS
Blog

Cron für Serverless: GitHub Actions, Vercel Cron und Cloudflare Workers

9 Min. Lesezeitvon DevToolBox
Ad Space

Cron-Ausdrücke sind die universelle Sprache für wiederkehrende Aufgaben. Serverless-Plattformen haben jeweils eigene Eigenheiten.

Cron-Grundlagen

Ein Standard-Cron hat 5 Felder:

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sun=0)
│ │ │ │ │
* * * * *

Häufige Sonderzeichen:

  • *beliebiger Wert
  • */5alle 5 Einheiten
  • 1,3,5bestimmte Werte
  • 1-5Wertebereich

Cron-Ausdrücke mit unserem Cron Parser testen →

Plattform 1: GitHub Actions

GitHub Actions nutzt das schedule-Event.

Konfiguration

# .github/workflows/scheduled.yml
name: Scheduled Job
on:
  schedule:
    - cron: '30 5 * * 1-5'  # Weekdays at 5:30 AM UTC
    - cron: '0 12 1 * *'    # 1st of every month at noon UTC
jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: echo "Running scheduled task"

Einschränkungen

AspektDetails
ZeitzoneNur UTC
MindestintervallAlle 5 Minuten (*/5 * * * *)
GenauigkeitVerzögerung möglich
BranchNur Default-Branch
DeaktivierungNach 60 Tagen Inaktivität

Häufige Zeitpläne

# Every 5 minutes
- cron: '*/5 * * * *'

# Every hour at minute 0
- cron: '0 * * * *'

# Daily at midnight UTC
- cron: '0 0 * * *'

# Daily at 9 AM Eastern (UTC-5, no DST)
- cron: '0 14 * * *'

# Weekdays at 8 AM UTC
- cron: '0 8 * * 1-5'

# Every Monday and Thursday at 6 PM UTC
- cron: '0 18 * * 1,4'

# First day of every month at midnight
- cron: '0 0 1 * *'

Tip: GitHub Actions kann verzögert auslösen.

Plattform 2: Vercel Cron Jobs

Konfiguration in vercel.json.

Konfiguration

// vercel.json
{
  "crons": [
    {
      "path": "/api/daily-report",
      "schedule": "0 8 * * *"
    },
    {
      "path": "/api/cleanup",
      "schedule": "0 0 * * 0"
    }
  ]
}

API-Route

// app/api/daily-report/route.ts
import { NextResponse } from 'next/server';

export async function GET() {
  // Your scheduled logic here
  await sendDailyReport();
  return NextResponse.json({ ok: true });
}

// Vercel recommends setting maxDuration for long tasks
export const maxDuration = 60; // seconds

Einschränkungen

PlanMin. IntervallMax Cron JobsLaufzeit
Hobby (free)Once per day210s
ProOnce per hour4060s (default)
EnterpriseOnce per minute100900s

Important: Vercel nutzt UTC. Hobby: 1x/Tag.

Plattform 3: Cloudflare Workers

Konfiguration in wrangler.toml.

Konfiguration

# wrangler.toml
name = "my-worker"
main = "src/index.ts"

[triggers]
crons = [
  "*/5 * * * *",    # Every 5 minutes
  "0 12 * * 1-5",   # Weekdays at noon UTC
  "0 0 1 * *"       # First of every month
]

Worker-Code

// src/index.ts
export default {
  async scheduled(
    controller: ScheduledController,
    env: Env,
    ctx: ExecutionContext
  ) {
    // controller.cron contains the cron pattern that triggered
    switch (controller.cron) {
      case '*/5 * * * *':
        await doHealthCheck(env);
        break;
      case '0 12 * * 1-5':
        await sendReport(env);
        break;
    }
  },
};

Einschränkungen

AspektDetails
ZeitzoneNur UTC
Mindestintervall1x pro Minute
Max cron triggers3 pro Worker (kostenlos)
CPU10ms/30s
GenauigkeitSehr zuverlässig

Plattformvergleich

FeatureGitHub ActionsVercel CronCF Workers
TimezoneUTCUTCUTC
Min interval (free)5 min1/day1 min
Min interval (paid)5 min1/min1 min
ReliabilityMedium (can delay)HighVery high
Max execution time6 hours10s-900s10ms-30s
Config location.github/workflows/vercel.jsonwrangler.toml
Trigger handlerWorkflow YAMLAPI routescheduled() event

Zeitzonen-Falle

Alle drei nutzen ausschließlich UTC.

LokalzeitUTC-OffsetCron (9h lokal)
US Eastern (EST)UTC-50 14 * * *
US Pacific (PST)UTC-80 17 * * *
Central Europe (CET)UTC+10 8 * * *
China (CST)UTC+80 1 * * *
Japan (JST)UTC+90 0 * * *

Sommerzeit ändert UTC-Offsets.

10 Copy-Paste Cron-Ausdrücke

Häufig benötigte Zeitpläne:

# Every 5 minutes
*/5 * * * *

# Every hour at :00
0 * * * *

# Every day at midnight UTC
0 0 * * *

# Every day at noon UTC
0 12 * * *

# Weekdays (Mon-Fri) at 9 AM UTC
0 9 * * 1-5

# Every Monday at 8 AM UTC
0 8 * * 1

# Every 6 hours
0 */6 * * *

# First day of every month at midnight
0 0 1 * *

# Every 15 minutes during business hours (8-17 UTC)
*/15 8-17 * * 1-5

# Last day of month at 11 PM UTC (approximate)
0 23 28-31 * *

Cron-Ausdrücke validieren →

Häufige Fragen

Welche Zeitzone nutzt GitHub Actions?

Immer UTC.

Mindestintervall Vercel Cron?

Hobby: 1/Tag, Pro: 1/Stunde, Enterprise: 1/Minute.

Cloudflare Workers jede Sekunde?

Nein. Mindestgranularität: 1 Minute.

Verwandte Tools ausprobieren

Cron Expression Parser
Ad Space

Verwandte Artikel

Docker Compose YAML-Validierung: 10 häufige Syntaxfehler und ihre Behebung

Verschwenden Sie keine Zeit mit Docker Compose YAML-Fehlern. Lernen Sie die 10 häufigsten Syntaxfehler zu erkennen und zu beheben.