Skip to main content

Cron Jobs

Run any Edge Function on a schedule — daily reports, weekly emails, monthly cleanups. Cron jobs use standard cron expression syntax and execute in the Africa/Lagos timezone (WAT, UTC+1) by default.

Overview

Attach a cron schedule to any existing function. NaijaBase will invoke the function automatically at the specified interval. The function receives an empty object {} as the request payload for scheduled runs (trigger type: cron).

Setting a Schedule (Dashboard)

  1. Open your project → Functions tab
  2. Select a function
  3. Click the Cron Schedule tab
  4. Enter a cron expression (e.g. 0 8 * * *)
  5. Click Set schedule

The next scheduled run time (in WAT) is shown immediately.

Setting a Schedule (API)

curl -X POST https://api.naijabase.dev/functions/FUNCTION_ID/cron \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"schedule": "0 8 * * *",
"timezone": "Africa/Lagos"
}'

Cron Expression Syntax

┌───── minute (0-59)
│ ┌───── hour (0-23, in WAT / UTC+1)
│ │ ┌───── day of month (1-31)
│ │ │ ┌───── month (1-12)
│ │ │ │ ┌───── day of week (0-7, 0 and 7 = Sunday)
│ │ │ │ │
* * * * *

Common Patterns

ExpressionDescription
0 8 * * *Every day at 8:00 AM WAT
0 9 * * 1Every Monday at 9:00 AM WAT
0 * * * *Every hour (on the hour)
*/30 * * * *Every 30 minutes
0 0 1 * *First of every month at midnight WAT
0 18 * * 5Every Friday at 6:00 PM WAT
0 7 * * 1-5Weekdays at 7:00 AM WAT
0 6,12,18 * * *Three times a day (6am, noon, 6pm WAT)

Nigerian Business Hours Reference

Time (WAT)Use case
0 6 * * 1-5Pre-market reports (banking opens 8am)
0 8 * * 1-5Morning digest emails
0 12 * * 1-5Midday summaries
0 17 * * 1-5End-of-business reports
0 22 * * *Nightly data cleanup (low-traffic window)

Example: Daily Summary Email

export default async function handler(req) {
// req will be {} when triggered by cron
const today = new Date().toLocaleDateString('en-NG', {
timeZone: 'Africa/Lagos',
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})

// Fetch your data, send emails, etc.
const summary = await fetchDailySummary()

await sendEmail({
to: 'team@yourcompany.com',
subject: `Daily Report — ${today}`,
body: summary,
})

return { sent: true, date: today }
}

Schedule it with 0 8 * * 1-5 to run every weekday at 8am WAT.

Example: Monthly Cleanup

export default async function handler(req) {
const thirtyDaysAgo = new Date()
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30)

// Delete old records (use your NaijaBase project credentials via env vars)
const response = await fetch(`${process.env.PROJECT_URL}/rest/v1/events`, {
method: 'DELETE',
headers: {
apikey: process.env.API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({ created_at: { lt: thirtyDaysAgo.toISOString() } }),
})

const deleted = await response.json()
return { deleted_count: deleted.length, ran_at: new Date().toISOString() }
}

Schedule: 0 2 1 * * — 2am WAT on the first of each month.

Plan Limits

PlanCron Jobs
Starter0
Growth0
Scale5
Business20
Compliance ProUnlimited

Removing a Schedule

To remove a cron schedule without deleting the function:

Dashboard: Functions → select function → Cron Schedule → Remove schedule

API:

curl -X DELETE https://api.naijabase.dev/functions/FUNCTION_ID/cron \
-H "Authorization: Bearer YOUR_JWT_TOKEN"

The function itself is not deleted — it can still be invoked via HTTP.

Execution Behaviour

  • Cron jobs run in the same isolated Docker container as HTTP invocations
  • If a previous run is still executing when the next one is scheduled, the new run starts anyway (no queue — concurrent runs are allowed)
  • Logs for cron runs appear in the function's Logs tab with trigger type cron
  • Failed runs (non-zero exit code or timeout) are logged as error but do not disable the schedule
  • Timezone: always Africa/Lagos (WAT, UTC+1) — no daylight saving adjustment needed