Skip to the content.

OneBlink API CLI

Scheduled Functions

Scheduled functions allow developers to run a function periodically. The function will be executed without any arguments. The schedule the functions run on will be determined by a team member in the Console after the function has been deployed. The schedule is not configured in source or as part of the deployment to allow customers to support the following use cases:

.blinkmrc.json

Functions are defined in your .blinkmrc.json file similar to routes. The following scheduled function definitions:

{
  "server": {
    "scheduledFunctions": [
      {
        "label": "Hello World",
        "name": "world",
        "module": "./src/hello.js",
        "export": "sayHelloWorld",
        "timeout": 10,
        "retryOnFail": true
      },
      {
        "label": "Hello Galaxy",
        "name": "galaxy",
        "module": "./src/hello.js",
        "export": "sayHelloGalaxy",
        "timeout": 5,
        "retryOnFail": false
      }
    ]
  }
}

With the following directory structure:

|-- project-root
|   |-- .blinkmrc.json
|   |-- src
|   |   |-- hello.js

With the src/hello.js file implemented as:

'use strict'

function sayHelloWorld() {
  console.log('Hello, World!')
}

function sayHelloGalaxy() {
  console.log('Hello, Galaxy!')
}

module.exports = {
  sayHelloWorld,
  sayHelloGalaxy,
}

Would result in two functions that could be scheduled separately.

Properties

label (required)

A human readable label for the function to display.

name (required)

A unique identifier for the function within the scope of the Hosted API.

module (required)

The relative path to the file to execute the function.

export (required)

The name of the exported function in the module to execute the function.

retryOnFail (required)

If set to true, the function will automatically retry twice if it fails.

timeout (optional)

The time in seconds allowed for the function to finish executing.