Skip to content

Cron

Cron triggers run your function automatically based on a cron expression. Instead of calling main({ input }), the scheduler now invokes your exported cron(data) handler.

Use main for direct/manual execution paths (such as HTTP), and add the cron handler to respond to scheduled invocations.

  • Expression format: minute hour day month weekday (UTC)
  • Examples: * * * * * (every minute), 0 * * * * (hourly), 0 9 * * 1-5 (weekdays 09:00)
  • Configure in the dashboard under Settings → Triggers → Cron
Cron trigger UI showing the schedule toggle, cron expression field, and upcoming run times
export async function cron(data: unknown) {
// handle scheduled invocation
}

The handler runs on the schedule you define. Return values are logged and surfaced in execution history, just like other triggers.

Note: data currently arrives as an empty object; custom payloads are not yet available for cron triggers.

The following function demonstrates exports for both manual invocations (main) and the new cron handler, plus an integration with @microfn/fn inside cron().

import fn from "@microfn/fn";
// Welcome to Microfn!
// This is a serverless function that runs in the cloud.
// Export a main function that takes { input: data } and returns any value.
// Strings/numbers are returned as-is, objects/arrays are JSON serialized.
export async function main({ input }) {
return {
message: "Hello from Microfn!",
timestamp: new Date().toISOString(),
receivedInput: input
};
}
export async function cron(data) {
// handle cron trigger
console.log("cron triggered");
const discordPayload = {
channelId: "1365582079387107400",
content: "corn 🌽",
};
const discordResult = await fn.executeFunction("david/send-discord-message", discordPayload);
return "corn";
}