Sanity Library Reference Docs
    Preparing search index...

    Function defineScheduledFunction

    • Defines a function that is triggered on a schedule. Supports cron expressions or natural language schedules.

      Parameters

      • functionConfig: BlueprintScheduledFunctionConfig

        The configuration for the scheduled function

        Configuration for defining a scheduled function.

        • OptionaldisplayName?: string

          Human-readable display name for the function

        • Optionalenv?: Record<string, string>

          Environment variables provided to the function

        • event: BlueprintScheduledFunctionConfigEvent

          Event configuration specifying when the function is triggered

        • Optionalmemory?: number

          Memory allocation in gigabytes

        • name: string

          The name of the resource. Unique within the blueprint. e.g. 'sync-webhook'

        • OptionalrobotToken?: string

          Token provided during function invocation

        • Optionalruntime?: "node" | "nodejs22.x" | "nodejs24.x"

          The runtime environment for the function (currently only Node.js is supported)

          'nodejs24.x'
          
        • Optionalsrc?: string

          Path to the function source code

          functions/${name}

        • Optionaltimeout?: number

          Execution timeout in seconds

        • Optionaltimezone?: IanaTimezone

      Returns BlueprintScheduledFunctionResource

      The validated scheduled function resource

      Using a cron expression:

      defineScheduledFunction({
      name: 'daily-cleanup',
      event: {expression: '0 9 * * *'},
      })

      Using explicit cron fields:

      defineScheduledFunction({
      name: 'daily-cleanup',
      event: {minute: '0', hour: '9', dayOfMonth: '*', month: '*', dayOfWeek: '*'},
      })

      The event.expression field accepts standard cron expressions or natural language: 'every 15 minutes', 'weekdays at 8am', 'fridays in the evening', 'mon, wed, fri at 9am', 'first of the month at noon'

      defineScheduledFunction({
      name: 'daily-cleanup',
      event: {expression: 'every day at 9am'},
      })