# Advanced Replication Scheduling Using Cron Expressions

Information note

**Advanced Scheduling is an upgraded feature**

Cron scheduling allows you to fine-tune an integration’s replication schedule, ensuring you have the data you need when you need it. [Contact Stitch Sales for more info](https://www.stitchdata.com/contact/?utm_medium=docs&utm_campaign=cron-scheduling).

For more info about Stitch Advanced, contact the [Stitch Sales team](https://www.stitchdata.com/contact/).

The Advanced Scheduler feature allows you to specify granular start times for data extraction. Using cron expressions, you can specify the exact times, days of the week, or even days of the month data extraction should begin.

**Note**: All replication scheduling methods (Replication Frequency, Anchor Scheduling, and Advanced Scheduling) define when data extractions begin. They do not control how long a replication job runs or when data is loaded into a destination.

In this guide, we’ll cover:

* [The uses for Advanced Scheduling](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#uses)

* [How to access Advanced Scheduling](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#access-advanced-scheduling)

* [The basics of cron scheduling](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#basics)

* [Examples of replication schedules using cron expressions](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#examples)

* [Limitations of cron scheduling in Stitch](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#limitations)

* [How to create an Advanced Schedule for an integration](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#create-schedule)

* [Additional cron resources](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#resources)

## Uses for Advanced Scheduling

Using Advanced Scheduling, you can:

1. **Run reports on specified days**. Using Advanced Scheduling, you can create a replication schedule that ensures reports for a weekly 9:00AM meeting are up-to-date.

2. **Whitelist hours for starting data extractions.** For example: Scheduling replication during off-peak hours will reduce load on your production database.

   **Note**: An extraction may run over into “blackout” hours as the Advanced Scheduler only controls the times jobs **start**. [See the Limitations section for more info](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#limitations).

3. **Reduce your row usage**. Only scheduling data extractions when you need them can not only reduce load on data sources and your destination, it can reduce your overall row usage in Stitch.

4. **Reduce the re-replication of data.** Because replication scheduling applies to all selected tables in an integration, tables using [Full Table Replication](https://help.qlik.com/en-US/stitch/replication/replication-methods/full-table) will replicate in full each time a replication job runs. Reducing the number of replication jobs overall will decrease the number of times the same record is replicated.

## Access to Advanced Scheduling

Advanced Scheduling is available during the Free Trial or on an Advanced or Premium plan. Contact [Stitch Sales](https://www.stitchdata.com/?utm_medium=docs&utm_campaign=cron-scheduling) for more info about these plans.

### Plan downgrades

When the Free Trial ends or if you downgrade from an Advanced or Premium plan, you’ll lose access to the Advanced Scheduling feature.

In the event that you downgrade, Stitch will automatically pause any integrations using Advanced Scheduling and reset their [Replication Frequencies](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/replication-frequency) to their defaults. You will need to manually un-pause the integrations to continue replication.

## Advanced Scheduling basics

Stitch’s Advanced Scheduler feature uses cron scheduling to create replication schedules. In this section, we’ll:

* [Introduce you to cron and cron expressions](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#intro-to-cron)

* [Describe cron expression syntax](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#cron-expression-syntax)

* [Explain how to use special characters](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#special-characters)

### Introduction to cron

So, what’s cron? **Cron** is a time-based scheduler used in Unix-like operating systems such as Mac OS, Linux, etc. Tasks, or jobs, created through cron are called **cron jobs**. Stitch uses the [Quartz standard](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling) for cron scheduling.

To create a cron job - in this case, an integration’s replication schedule - a **cron expression** is used. A cron expression describes the details of the schedule, and when combined, translates to the schedule Stitch will use to extract data from the integration.

Using a cron expression, you can create replication schedules such as *“At 12:00AM every day”* or *“At 7:00PM every Monday, Wednesday, and Friday”*. Stitch will then start replication jobs at these times.

### Cron expression syntax

A cron expression in Stitch is made up of six fields that describe the elements of the schedule, separated by spaces.

Fields in the expression must be in the following order, and an expression must have all six fields to be considered valid:

```
[seconds] [minute] [hour] [day of month] [month] [day of week]
```

**Note**: The expression uses UTC time. The time zone cannot be customized, but the corresonding local time is displayed in the **Sample schedule (local time)** when creating the expression.

Fields can contain any of the allowed values, along with various combinations of the allowed special characters for that field. **Note**: Entering anything other than a field’s allowed values or special characters will result in an error when you try to save the integration’s settings. Refer to the [Troubleshooting section](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#troubleshooting-cron-errors) for help resolving these errors.

| **Name** | **Allowed values** | **Allowed special characters** |
| --- | --- | --- |
| Seconds | 0<br><br>the Warning 2 icon<br><br>&lt;p&gt;This field’s value of 0 is pre-defined and cannot be modified.&lt;/p&gt; | n/a |
| Minutes | 0-59 | , - \* / |
| Hours | 0-23 | , - \* / |
| Day of month | 1-31<br><br>the Warning 2 icon<br><br>&lt;p&gt;If this field is defined, the &lt;strong&gt;Day of week&lt;/strong&gt; field must contain a ? value. Refer to the for more info.&lt;/p&gt; | , - \* ? / L W |
| Month | 1-12 or JAN-DEC | , - \* / |
| Day of week | 1-7 or SUN-SAT<br><br>the Warning 2 icon<br><br>&lt;p&gt;If this field is defined, the &lt;strong&gt;Day of month&lt;/strong&gt; field must contain a ? value. Refer to the for more info.&lt;/p&gt; | , - \* ? / L # |

### Allowed special characters

Each field in a cron expression has its own list of allowed special characters. These characters allow you to select all values, a list or range of values, specify increments, and more. Fields may also contain both a range and a list. Refer to the [Example replication schedules section](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#examples) for examples.

| **Special character** | **Allowed in** | **Description and examples** |
| --- | --- | --- |
| **`*`**<br><br><br>ASTERISK | All fields | Selects all values within a field.<br><br>**Examples:**<br><br><ul> <li><code>*</code> in the <strong>Minute</strong> field means <em>“every minute”</em></li> <li><code>*</code> in the <strong>Hour</strong> field means <em>“every hour”</em></li> <li><code>*</code> in the <strong>Month</strong> field means <em>“every month”</em></li> <li><code>*</code> in the <strong>Day of week</strong> field means <em>“every day of the week”</em></li></ul> |
| **`,`**<br><br><br>COMMA | All fields | Specifies a list of two or more values.<br><br>**Examples:**<br><br><ul> <li><code>1,2,5</code> or <code>JAN,FEB,MAY</code> in the <strong>Month</strong> field means <em>“the months January, February, and May”</em></li> <li><code>2,6</code> or <code>MON,FRI</code> in the <strong>Day of week</strong> field means <em>“the days Monday and Friday”</em></li></ul> |
| **`-`**<br><br><br>HYPHEN | All fields | Specifies a range of values.<br><br>**Examples:**<br><br><ul> <li><code>5-8</code> in the <strong>Hour</strong> field means <em>“the hours 5, 6, 7, and 8”</em></li> <li><code>2-4</code> or <code>MON-WED</code> in the <strong>Day of week</strong> field means <em>“the days Monday, Tuesday, and Wednesday”</em></li></ul> |
| **`?`**<br><br><br>QUESTION MARK | Day of month, Day of week | Indicates *“no specific value”*. This character is useful when you need to specify something in either the **Day of month** or **Day of week** field, but not the other.<br><br>**Note**: Quartz doesn’t currently support specifying a value for both the **Day of week** and **Day of month** fields. This value must be present in one of these fields for the expression to be valid.<br><br>**Examples:**<br><br><ul> <li><code>15</code> in the <strong>Day of month</strong> field and <code>?</code> in the <strong>Day of week</strong> field means <em>“the 15th day of the month, regardless of the day of the week”</em></li></ul> |
| **`/`**<br><br><br>SLASH | All fields | Specifies increments. Formatted as: `<value>/<value_to_increment`&gt;<br><br>**Examples:**<br><br><ul> <li><code>0/15</code> in the <strong>Minute</strong> field means <em>“the minutes 0, 15, 30, and 45”</em></li> <li><code>3/6</code> in the <strong>Hour</strong> field means <em>“every 6 hours beginning on the third hour”</em></li> <li><code>1/5</code> in the <strong>Day of month</strong> field means <em>“every 5 days beginning on the first day of the month”</em></li></ul> |
| **`L`**<br><br><br>LAST | Day of month, Day of week | Depending on the field `L` is used in, this can have different meanings:<br><br><ul> <li><strong>Day of month</strong>: Used to indicate the last day of the month.</li> <li> <p><strong>Day of week</strong>: If used by itself, this means <code>7</code>, or <code>SAT</code>.</p> <p>If used after another value in this field (for example: <code>6L</code>), this means <em>“the last [xxx] day of the month”</em>.</p> </li></ul><br><br>To avoid confusing or unexpected results, don’t specify lists or ranges of values with `L`.<br><br>**Examples:**<br><br><ul> <li><code>L</code> in the <strong>Day of month</strong> field means <em>“the last day of the month”</em>, such as January 31 or February 28 (or 29 during a leap year)</li> <li><code>6L</code> or <code>FRIL</code> in the <strong>Day of week</strong> field means <em>“the last Friday of the month”</em></li></ul> |
| **`W`**<br><br><br>WEEKDAY | Day of month | Specifies the weekday (Monday - Friday) closest to the given day. **Note**: This character is only allowed when the **Day of month** value is a single day, not a range or list of days.<br><br>`L` can also be combined with `W` in the **Day of month** field to indicate *“the last weekday of the month”*.<br><br>**Examples:**<br><br><ul> <li><code>15W</code> means <em>“the nearest weekday to the 15th of the month”</em>. If the 15th were a Saturday, a replication job would begin on Friday the 14th.</li> <li><code>1W</code> means <em>“the nearest weekday to the 1st of the month”</em>. If the 1st is a Saturday, the replication job would begin on Monday the 3rd. Advanced scheduling can’t skip over a boundary of days.</li> <li><code>LW</code> means <em>“the last weekday of the month”</em></li></ul> |
| **`#`**<br><br><br>HASH | Day of week | Specifies the `nth` day of the month, such as *“the third Friday of the month”*. This is used with a day of week value (`1-7` or `SUN-SAT`) and an integer of `1-5`, formatted as `<day_of_week_value>#<integer>`.<br><br>**Note**: If `<day_of_week_value>#5` is specified and there isn’t a fifth given day of week in the month, then the replication job will not be triggered.<br><br>**Examples:**<br><br><ul> <li><code>4#2</code> or <code>WED#2</code> means <em>“the second Wednesday of the month”</em></li> <li><code>2#1</code> or <code>MON#1</code> means <em>“the first Monday of the month”</em></li> <li><code>7#5</code> or <code>SAT#5</code> means <em>“the fifth Saturday of the month”</em>. If a month doesn’t have five Saturdays, a replication job will not be triggered.</li></ul> |

## Example replication schedules

Information note **Tip:** **Want to test an expression?** Try the [Quartz Cron Expression Generator](https://www.freeformatter.com/cron-expression-generator-quartz.html).

Based on scheduling feedback we’ve collected, we’ve put together a list of some of the most commonly requested replication schedules. You can use these examples to define an integration’s replication schedule in Stitch, or create your own. Keep in mind that there are some [limitations](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#limitations).

* [Run at midnight UTC every day](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#at-midnight-every-day)

* [Run at midnight UTC every day from Monday through Friday](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#midnight-every-day-mon-fri)

* [Run once a week at 11:00PM UTC on Sunday](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#sunday-11pm)

* [Run at noon and midnight UTC every day](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#noon-and-midnight)

* [Run Tuesday through Thursday every week at 3:00AM UTC](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#tue-thur-3am)

* [Run at midnight UTC every Monday, Wednesday, and Friday](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#midnight-mon-wed-fri)

* [Run at minute 30 and every minute between :05 and :10, every hour, every day in January](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#minutes-hours-in-january)

### Run at midnight UTC every day

| **Seconds** | **Minutes** | **Hours** | **Day-of-month** | **Month** | **Day-of-week** |
| --- | --- | --- | --- | --- | --- |
| 0 | 0 | 0 | ? | \* | \* |
| 0 | 0 | 0 | \* | \* | ? |

### Run at midnight UTC every day from Monday through Friday

| **Seconds** | **Minutes** | **Hours** | **Day-of-month** | **Month** | **Day-of-week** |
| --- | --- | --- | --- | --- | --- |
| 0 | 0 | 0 | ? | \* | 2-6 |
| 0 | 0 | 0 | ? | \* | MON-FRI |

### Run once a week at 11:00PM UTC on Sunday

| **Seconds** | **Minutes** | **Hours** | **Day-of-month** | **Month** | **Day-of-week** |
| --- | --- | --- | --- | --- | --- |
| 0 | 0 | 23 | ? | \* | 1 |
| 0 | 0 | 23 | ? | \* | SUN |

### Run at noon and midnight UTC every day

| **Seconds** | **Minutes** | **Hours** | **Day-of-month** | **Month** | **Day-of-week** |
| --- | --- | --- | --- | --- | --- |
| 0 | 0 | 0,12 | \* | \* | ? |
| 0 | 0 | 0,12 | ? | \* | \* |

### Run Tuesday through Thursday every week at 3:00AM UTC

| **Seconds** | **Minutes** | **Hours** | **Day-of-month** | **Month** | **Day-of-week** |
| --- | --- | --- | --- | --- | --- |
| 0 | 0 | 3 | ? | \* | 3-5 |
| 0 | 0 | 3 | ? | \* | TUE-THUR |

### Run at midnight UTC every Monday, Wednesday, and Friday

| **Seconds** | **Minutes** | **Hours** | **Day-of-month** | **Month** | **Day-of-week** |
| --- | --- | --- | --- | --- | --- |
| 0 | 0 | 0 | ? | \* | 2,4,6 |
| 0 | 0 | 0 | ? | \* | MON,WED,FRI |

### Run at minute 30 and every minute between :05 and :10, every hour, every day in January

| **Seconds** | **Minutes** | **Hours** | **Day-of-month** | **Month** | **Day-of-week** |
| --- | --- | --- | --- | --- | --- |
| 0 | 5-10,30 | \* | ? | 1 | \* |
| 0 | 5-10,30 | \* | \* | 1 | ? |

## Limitations of cron scheduling

While using cron expressions will give you the most control over your integrations’ replication schedules, there are some limitations to keep in mind:

1. **You can specify a Day of week OR Day of month value, but not both**. Quartz, the cron implementation used by Stitch, [doesn’t currently support specifying values for both fields in an expression](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html#notes). One of these fields must contain the `?` character for the expression to be considered valid.

2. **Advanced Scheduling can only be used to whitelist extraction start times**. This means that a job could start during a whitelisted time period but continue running beyond that window, depending on the duration of the extraction.

   For example: An integration has a schedule that tells it to run every 20 minutes between the hours of noon and 2:00PM, starting at noon.

   On average, extractions for this integration take between 2-5 minutes. However, the extraction that starts at 1:40PM takes longer than average, causing the job to continue running even after the 2:00PM mark. As a result, the job scheduled for 2:00PM will be skipped and resume at the next scheduled interval.

## Create an Advanced Schedule for an integration

You can create an Advanced Schedule in an integration’s **Settings** page.

1. To access this page, click the integration from the Stitch Dashboard and then click the **Settings** tab.

2. In the **Replication Frequency** section, check the **Advanced** box located under the **Anchor time** menu. This will open the **Advanced Scheduler**.

   **Note**: This feature is only available [during the Free Trial or on an Advanced or Premium plan](https://help.qlik.com/en-US/stitch/replication/replication-scheduling/advanced-scheduling#access-advanced-scheduling).

3. Enter the values you want into each of the fields. Stitch will validate the schedule after each change. If the schedule is valid, a sample schedule will display under the fields.

4. When finished, click the **Save Integration** button.

## Additional cron resources

* [**Quartz Scheduler**](http://www.quartz-scheduler.org/) - The official documentation for the Quartz Scheduler.

* [**Quartz Cron Trigger Tutorial**](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html) - A cron tutorial from the makers of Quartz, the cron implementation used in Stitch.

* [**Quartz Cron Expression Generator**](https://www.freeformatter.com/cron-expression-generator-quartz.html) - A simple, web-based editor for Quartz cron expressions.