Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scheduler.md #178

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 44 additions & 40 deletions docs/reference-docs/scheduler.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
# Scheduling Workflows

Sometimes, we need a workflow to run on a regular cadence. For such use cases we can use the Scheduler functionality that is provided by Conductor. Using a crontab expression, we can configure workflows to be triggered at any cadence as required.
Sometimes, you need a workflow to run on a regular cadence. For such use cases, you can use the Scheduler functionality provided by Conductor. You can configure workflows to be triggered at any cadence as required using a crontab expression.

We can use the scheduler for use cases such as:
You can use the scheduler for use cases such as:

* Running a workflow in a fixed cadence such as every hour
* Running the same workflow at different cadences using different fixed inputs
* Running a workflow at a cadence between a fixed start date and end date
* Running the workflow once at a future date
* Running a workflow in a fixed cadence, such as every hour.
* Running the same workflow at different cadences using different fixed inputs.
* Running a workflow at a cadence between a set start date and an end date.
* Running the workflow once at a future date.


<p align="center"><iframe width="560" height="315" src="https://www.youtube.com/embed/S5Ya4BP7wRk" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>


## Creating a Schedule

Conductor offers a configuration UI to create and manage a schedule. Alternatively we can create one via the API.
Conductor offers a configuration UI to create and manage a schedule. Alternatively, you can create one via the API.

## UI Schedule Creation

To create a schedule, click ```Scheduler Definitions``` in the left navigation. This will display a list of all of our defined schedules. Click the [Define Schedule](https://play.orkes.io/scheduler/newScheduleDef) button in the upper right corner. Fill in the form with the following parameters:
For creating a schedule via Conductor UI,
1. Navigate to **Scheduler** and click **Definitions**. This will display a list of all our defined schedules.
2. Click the **Define Schedule** button in the upper right corner.

* **Schedule Name**: A descriptive term for the schedule being created (will appear in the ```Schedule Definitions``` list). (No spaces or special characters)
* **Cron Expression**: The schedule that the workflow will run on (see [Cron Expression](#cron-expression) below.)
* **Workflow Name**: The name of the workflow to be run. The author of the schedule should have execution permission for the workflow
* **Workflow Version**: The version of the workflow. If left blank, the latest version will be run.
* **Input Parameters**: Any fixed input values for the workflow as a JSON object (optional)
* **Correlation Id**:
* **Schedule Start**: Time/date that the schedule will start running (optional) (inclusive)
* **Schedule End**: Time/date that the schedule will stop running (optional) (inclusive)
* **Task to Domain Mapping**: (optional)
* **Schedule Paused**: If selected, the schedule will be paused (so it will not run) upon creation
You need to fill in the form with the following parameters:

* **Schedule Name**: Provide a unique name for the schedule to be created. It can be used to identify your schedule from the **Workflow Scheduler Definitions** list. Ensure that the schedule name contains no spaces or special characters.
* **Cron Expression**: The cron expression is the schedule that the workflow will run on. You can either input the cron expression or choose from the available templates. See the section [Cron Expression](#cron-expression) below for detailed information regarding this.
* **Workflow Name**: Provide the name of the workflow to be run. The author of the schedule should have execution permission for the workflow. Else the workflow would get terminated quoting the reason that the author has no permission over the workflow.
* **Workflow Version**: The Workflow created may have different versions. You can choose the version to be scheduled here. If left blank, it will run the latest version.
* **Input Parameters**: Any fixed input values for the workflow as a JSON object. This field is optional.
* **Correlation Id**: A user-supplied ID used to identify the workflows.
* **Schedule Start**: Choose the date & time for the schedule to start running. It should be in the format *yyyy-mm-dd hh:mm (a|p)m*. This field is optional.
* **Schedule End**: Choose the date & time for the schedule to stop running. It should be in the format *yyyy-mm-dd hh:mm (a|p)m*. This field is optional.
* **Task to Domain Mapping**: You can leverage this option to debug and develop even while running in the production environment. You need to provide the task to domain mapping as a JSON file. This field is optional.
* **Start Schedule Paused?**: If selected, the schedule will be paused (so it will not run) upon creation. It is helpful when you don’t want to run the workflow scheduler, such as during maintenance. So to re-run the scheduler, you need to edit the scheduler and disable this option.

## API Schedule Creation

Expand All @@ -50,7 +54,7 @@ Send a POST with
* correlationId (optional)
* taskToDomain (optional)

An example API call (using the [Orkes Playground](https://play.orkes.io)) looks like:
An example API call looks like this: (You can try it out using the [Orkes Playground](https://play.orkes.io))


```bash
Expand All @@ -69,47 +73,47 @@ curl -i -X "POST" "https://play.orkes.io/api/scheduler/schedules" \
}'
```

> Note: If using Orkes Conductor or the Orkes Playground, our API call must be [authenticated](https://orkes.io/content/docs/getting-started/concepts/access-control), and our application must have execute permissions for the workflow in question.
> **Note**: If you are using Orkes Conductor or the Orkes Playground, our API call must be [authenticated](https://orkes.io/content/docs/getting-started/concepts/access-control), and our application must have execute’ permission for the workflow.

## Cron expression
## Cron Expression

The UI has a *Cron Expression Helper* to describe the options of the Cron expression. We can also test our expression after entering it - and the UI will calculate the next few times of the schedule.
The UI has a *Cron Expression Helper* to describe the options of the Cron expression. You can also test our expression after entering it - and the UI will automatically calculate the next few runs of the schedule.

The CRON expression has 6 terms, and a blank entry is denoted by an asterisk.
The CRON expression has six terms; you can denote a blank entry with an asterisk.

```
* * * * * *
```

The terms, in order left to right define the timings:
The terms, in order from left to right, define the timings:

* **Second**: Allowed values: 0-59
* **Minute**: Allowed values: 0-59
* **Hour**: Allowed values: 0-23
* **Day of Month**: (1-31)
* **Month**: (1-12 or Jan-Dec)
* **Day of Week**: (0-7 or MON-SUN) [0 & 7 are Sunday]
* **Day of Month**: Allowed values: 1-31.
* **Month**: Allowed values are 1-12 or JAN-DEC.
* **Day of Week**: Allowed values are 0-7 or MON-SUN, where 0 & 7 is Sunday.

There are a number of examples on the definition page we can use as an aid to set the schedule.
There are several examples on the definition page that you can use to set the schedule.

Macros are also supported when setting a schedule
Macros are also supported when setting a schedule.

|Macro |Meaning|
| --- | ----------- |
|@yearly (or @annually)|once a year (0 0 0 1 1 *)|
|@monthly|once a month (0 0 0 1 * *)|
|@weekly|once a week (0 0 0 * * 0)|
|@daily (or @midnight)|once a day (0 0 0 * * *)|
|@hourly |once an hour, (0 0 * * * *)|
|@yearly (Or @annually)|Once a year (0 0 0 1 1 *)|
|@monthly|Once a month (0 0 0 1 * *)|
|@weekly|Once a week (0 0 0 * * 0)|
|@daily (Or @midnight)|Once a day (0 0 0 * * *)|
|@hourly |Once an hour, (0 0 * * * *)|

## Things to Note

* The schedules are all based on **UTC** timezone
* The scheduler supports up to a second granularity - however this is on a best effort basis. A minimum of a 30 seconds gap is recommended as the cadence for workflow schedules
* We can have multiple schedules invoking the same workflow
* Execution history is maintained up to a configured maximum limit (default of 1000 executions per schedule)
* When running a very large number of schedules, we need to tune the configurations to configure the server
* When the workflow is invoked, it will have the following field injected as input automatically
* The schedules are all based on the **UTC** timezone.
* The scheduler supports up to a second granularity - however, this is on a best-effort basis. A minimum of a 30 seconds gap is recommended as the cadence for workflow scheduling.
* You can have multiple schedules invoking the same workflow.
* Execution history is maintained up to a configured maximum limit (Default of 1000 executions per schedule).
* When running many schedules, you must tune the configurations to configure the server.
* When the workflow is invoked, it will have the following field injected as input automatically.
```json
{
"_executedTime": <EPOCH EXECUTED TIME>,
Expand Down