Set Schedule

In the UI, you can set a time schedule for orchestration. Via the API you can set a time schedule for any configuration or even multiple schedules for a single configuration.

Assuming, you have already setup of any configuration (including Orchestrator and Flow) and you can successfully run it through the UI or through the API. Look at the successful job:

Screenshot -- Job Parameters

In the job detail, you can see the parameters required to run the configuration, in this case:

mode: run
component: keboola.ex-db-snowflake
config: 493493

To create a schedule, you have to create the schedule configuration first using the Create Configuration API call. With the contents similar to this:

{
    "schedule": {
        "cronTab": "0 * * * *",
        "timezone": "UTC",
        "state": "enabled"
    },
    "target": {
        "componentId": "keboola.ex-db-snowflake",
        "configurationId": "493493",
        "mode": "run"
    }
}

The cronTab field defines the schedule in cronTab expression format. The target defines which configuration should be run. In the above example we use the same configuration from the job. To create the configuration itself, use the keboola.scheduler component (see an example):

curl --location --request POST 'https://connection.keboola.com/v2/storage/components/keboola.scheduler/configs/' \
--header 'X-StorageApi-Token: YOUR_TOKEN' \
--form 'name="Example Schedule"' \
--form 'configuration="{
    \"schedule\": {
        \"cronTab\": \"0 * * * *\",
        \"timezone\": \"UTC\",
        \"state\": \"enabled\"
    },
    \"target\": {
        \"componentId\": \"keboola.ex-db-snowflake\",
        \"configurationId\": \"493493\",
        \"mode\": \"run\"
    }
}"'

Take care to use the right endpoint depending on which Stack are you using. You’ll see Invalid access token error message if you are using the wrong endpoint or token. An example request response will contain:

{
    "id": "10850624",
    "name": "Example Schedule",
    "description": "",
    "created": "2022-01-31T00:00:59+0100",
    "creatorToken": {
        "id": 25144,
        "description": "Run Job"
    },
    "version": 1,
    "changeDescription": "Configuration created",
    "isDisabled": false,
    "isDeleted": false,
    "configuration": {
        "schedule": {
            "cronTab": "0 * * * *",
            "timezone": "UTC",
            "state": "enabled"
        },
        "target": {
            "componentId": "keboola.ex-db-snowflake",
            "configurationId": "493493",
            "mode": "run"
        }
    },
    "state": {},
    "currentVersion": {
        "created": "2022-01-31T00:00:59+0100",
        "creatorToken": {
            "id": 25144,
            "description": "Run Job"
        },
        "changeDescription": "Configuration created"
    }
}

The important field is id (with value 10850624 in the above example). In the second step, you need to activate the schedule via the Activate Schedule API call with he following body:

{
    "configurationId": "10850624"
}

See an example):

curl --location --request POST 'https://scheduler.azure.keboola.com/schedules' \
--header 'X-StorageApi-Token: YOUR_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "configurationId": "10850624"
}
'

Note: You have to use a Master Token to execute the above API call.

Configure Schedule for Row

If the configuration you’re scheduling uses Configuration rows, you can also schedule individual rows. Assuming you have a job running a single row:

Screenshot -- Row Parameters

You will see the the following in job parameters:

mode: run
component: keboola.ex-db-snowflake
config: 493493
row: 48094

Create a new scheduler configuration with the following configuration contents:

{
    "schedule": {
        "cronTab": "10,20,30,40,50 * * * *",
        "timezone": "UTC",
        "state": "enabled"
    },
    "target": {
        "componentId": "keboola.ex-db-snowflake",
        "configurationId": "493493",
        "configurationRowIds": ["48094"],
        "mode": "run"
    }
}

See example:

curl --location --request POST 'https://connection.keboola.com/v2/storage/components/keboola.scheduler/configs/' \
--header 'X-StorageApi-Token: YOUR_TOKEN' \
--form 'name="Example Row Schedule"' \
--form 'configuration="{
    \"schedule\": {
        \"cronTab\": \"10,20,30,40,50 * * * *\",
        \"timezone\": \"UTC\",
        \"state\": \"enabled\"
    },
    \"target\": {
        \"componentId\": \"keboola.ex-db-snowflake\",
        \"configurationId\": \"493493\",
        \"configurationRowIds\": [\"48094\"],
        \"mode\": \"run\"
    }
}"'

You’ll obtain the following example:

{
    "id": "10852379",
    "name": "Example Row Schedule",
    "description": "",
    "created": "2022-01-31T00:42:15+0100",
    "creatorToken": {
        "id": 322,
        "description": "ondrej.popelka@keboola.com"
    },
    "version": 1,
    "changeDescription": "Configuration created",
    "isDisabled": false,
    "isDeleted": false,
    "configuration": {
        "schedule": {
            "cronTab": "10,20,30,40,50 * * * *",
            "timezone": "UTC",
            "state": "enabled"
        },
        "target": {
            "componentId": "keboola.ex-db-snowflake",
            "configurationId": "493493",
            "configurationRowIds": [
                "48094"
            ],
            "mode": "run"
        }
    },
    "state": {},
    "currentVersion": {
        "created": "2022-01-31T00:42:15+0100",
        "creatorToken": {
            "id": 322,
            "description": "ondrej.popelka@keboola.com"
        },
        "changeDescription": "Configuration created"
    }
}

The created configuration has id 10852379. You can now Activate the Schedule with he following body:

{
    "configurationId": "10852379"
}

See an example):

curl --location --request POST 'https://scheduler.keboola.com/schedules' \
--header 'X-StorageApi-Token: YOUR_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "configurationId": "10852379"
}
'

This also demonstrates that you can set multiple schedules for a single configuration. In this case, the configuration 10852379 of the keboola.ex-db-snowflake will be executed at the beginning of every hour. Then the row 48094 of this configuration will also be executed every 10 minutes. To list the schedules use the Get Schedules API call – (see example). You’ll get a response similar to this:

[
    {
        "id": "743",
        "tokenId": "25147",
        "configurationId": "10850624",
        "configurationVersionId": "1",
        "schedule": {
            "cronTab": "0 * * * *",
            "timezone": "UTC",
            "state": "enabled"
        },
        "target": {
            "componentId": "keboola.ex-db-snowflake",
            "configurationId": "493493",
            "configurationRowIds": [],
            "mode": "run",
            "tag": ""
        },
        "executions": []
    },
    {
        "id": "744",
        "tokenId": "25148",
        "configurationId": "10852379",
        "configurationVersionId": "1",
        "schedule": {
            "cronTab": "10,20,30,40,50 * * * *",
            "timezone": "UTC",
            "state": "enabled"
        },
        "target": {
            "componentId": "keboola.ex-db-snowflake",
            "configurationId": "493493",
            "configurationRowIds": [
                "48094"
            ],
            "mode": "run",
            "tag": ""
        },
        "executions": []
    }
]