# Trigger CC with a Schedule

A CloudCode Task can be run on a schedule, e.g. every Monday at 8am, or every hour.

This is especially useful for recurring scripts or reports that need to be generated.

{% hint style="info" %}
**Limit a task to a single instance**

Limit your CloudCode Task to a single instance (available under the task's settings) when running a CloudCode task on a schedule to avoid duplicate instances running at the same time, which may cause data inconsistencies.
{% endhint %}

### Schedule types

For tasks running on a schedule, two high-level schedule types are available:

1. Task-based schedules.
2. Deployment-based schedules.

#### Task-based schedules

Task-based schedules are where the task will run at the same interval/times no matter the deployment. This is the quickest way to configure a CloudCode schedule.&#x20;

Once you have selected "Task-based" as your schedule mode, [set your schedule using the instructions below](#setting-a-schedule).

#### Deployment-based schedules

With deployment-based schedules developers can choose different intervals to run the task depending on the deployment. An example of where this is very useful is where you want to run a task more frequently in production deployments, and less frequently in testing deployments.

To set up a deployment-based schedule, follow these steps:

First, create a CloudCode schedule from any deployment's settings, under the "CloudCode Schedules" tab:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FDmeJlFlKeS331xszijwO%2FScreenshot%202022-09-05%20at%2010.50.07.png?alt=media&#x26;token=d705a8a5-bb37-4b80-9264-e7f411314f88" alt=""><figcaption></figcaption></figure>

Then, set your schedule for this deployment. More instructions can be [found below](#setting-a-schedule).

Save the schedule.

Now you need to create schedules for the other deployments. The quickest way to do that is to use the "Clone schedule" button:

Open the deployment settings for the deployment you want to clone a schedule to. Then choose the schedule you want to clone. You can edit the schedule so that the task will run at the appropriate intervals for this deployment.

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2Ff0WQYbSpJ1zZk7MqQEV9%2FScreenshot%202022-09-05%20at%2010.56.14.png?alt=media&#x26;token=0c299bf6-f426-46a2-826a-faa520ad5544" alt=""><figcaption></figcaption></figure>

Repeat this for all deployments where you want the CloudCode task to run.

Once this is complete, open the CloudCode task's settings:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FR2cfGex7XHUUExst6QvB%2FScreenshot%202022-09-05%20at%2010.57.35.png?alt=media&#x26;token=c8e2929e-5f49-4122-894d-a04bc5f3eb79" alt=""><figcaption></figcaption></figure>

Under the "Schedule" tab, select the "Deployment-based schedule" type and pick the CloudCode schedule you just created.

You should now be able to see in which deployments the schedule is defined:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2Fp50opZWvZ74MnbAiKClp%2FScreenshot%202022-09-05%20at%2010.57.56.png?alt=media&#x26;token=95feebec-5d04-4663-bf93-22e62c2ab3aa" alt=""><figcaption></figcaption></figure>

Clicking on one of the listed deployments allows you to edit the schedule for that deployment.

{% hint style="success" %}
**Reuse deployment-based schedules**

Sometimes it might be convenient to reuse the same deployment-based schedule for multiple tasks. This allows you to create a single set of schedules that can be updated in one place, instead of having multiple schedules across different tasks.
{% endhint %}

### Setting a schedule

Once you have chosen OXIDE gives you two modes to specify your schedule:

1. Using the simplified UI (called Simple mode)
2. Using a valid [Cron](https://en.wikipedia.org/wiki/Cron) expression (called Advanced mode)

Here's what it looks like in OXIDE:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2Fpxez70nv7f39xEm9z2GO%2FScreenshot%202022-09-05%20at%2010.41.56.png?alt=media&#x26;token=79dc88ad-3edb-4912-9793-1527efe73811" alt=""><figcaption><p>Scheduling using simple mode</p></figcaption></figure>

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FrGyc7LooTeqbwtIJ7eBH%2FScreenshot%202022-09-05%20at%2010.44.01.png?alt=media&#x26;token=ce135329-719f-4393-a487-2ff2f5674a83" alt=""><figcaption><p>Scheduling with advanced mode</p></figcaption></figure>

To set a schedule:

1. Right-click on the relevant CloudCode task in OXIDE, and open the task's settings.
2. Under the schedule tab, enable the schedule and configure it.
3. Save the schedule
