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

docs: rewrite schedules section #777

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Binary file removed sources/platform/images/schedule-actor-run.png
Binary file not shown.
Binary file removed sources/platform/images/schedule-add-tasks.png
Binary file not shown.
Binary file removed sources/platform/images/schedule-settings.png
Binary file not shown.
Binary file removed sources/platform/images/schedule-setup.png
Binary file not shown.
Binary file added sources/platform/images/schedules-actor-input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sources/platform/images/schedules-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sources/platform/images/schedules-setup-tool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sources/platform/images/schedules-task-input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 56 additions & 51 deletions sources/platform/schedules.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,84 @@ category: platform
slug: /schedules
---

# Schedules

**Learn how to automatically start your Actor and task runs and the basics of cron expressions. Set up and manage your schedules from Apify Console or via API.**

---

[Schedules](https://console.apify.com/schedules) allow you to run your Actors and tasks at specific times. You schedule the run frequency using [cron expressions](#cron-expressions).
Schedules allow you to run your Actors and tasks at specific times. You schedule the run frequency using [cron expressions](#cron-expressions).

:::note Timezone & Daylight Savings Time
valekjo marked this conversation as resolved.
Show resolved Hide resolved
Schedules allow timezone settings and support daylight saving time shifts (DST).
:::

There are few ways you can set up and manage your Schedules:

> Schedules allow timezone settings and support daylight saving time shifts (DST).
* [Apify Console](https://console.apify.com/schedules)
* [Apify API](https://docs.apify.com/api/v2#/reference/schedules)
* [JavaScript API client](https://docs.apify.com/api/client/js/reference/class/ScheduleClient)
* [Python API client](https://docs.apify.com/api/client/python/reference/class/ScheduleClient)

You can set up and manage schedules from
[Apify Console](https://console.apify.com/schedules)
and via [API](/api/v2#/reference/schedules)
(also with the
[JavaScript](/api/client/js/reference/class/ScheduleClient) and
[Python](/api/client/python/reference/class/ScheduleClient)
API clients).
When scheduling a new Actor or task run, you can override its input settings using a JSON object similarly to when invoking a schedule using the [Apify API](/api/v2#/reference/schedules/).
When scheduling a new Actor or task run, you can override its input settings using a JSON object similarly to when invoking a schedule using the [Apify REST API](/api/v2#/reference/schedules/).
TC-MO marked this conversation as resolved.
Show resolved Hide resolved

> In most cases, scheduled events are fired within one second of their scheduled time. <br/>
> Occasionally, however, runs can be delayed because of a system overload or a server shutting down.
:::note Events Startup Variability
In most cases, scheduled events are fired within one second of their scheduled time. <br/>
Occasionally, however, runs can be delayed because of a system overload or a server shutting down.
:::

Each schedule can be associated with a maximum of 10 Actors and 10 Actor tasks.
Each schedule can be associated with a maximum of _10_ Actors and _10_ Actor tasks.

## Setting up a new schedule

Before setting up a new schedule, you should have the [Actor](./actors/index.mdx) or [task](./actors/running/tasks.md) whose run you want to schedule prepared and tested.

If you are planning to schedule an Actor run, you need to use the Actor before you can schedule any runs. Navigate to the Actor's page in [Apify Store](https://apify.com/store), click the **Try for free** button, then **Start** it with your preferred settings.
To schedule an Actor, you need to have run it at least once before. To run the Actor, navigate to the Actor's page in [Apify Store](https://apify.com/store), and click the **Try for free** button. This will direct you to Apify Console, where you can configure and initiate the Actor's run with your preferred settings. After this initial run, you can then use Schedules to automate future runs of the Actor
TC-MO marked this conversation as resolved.
Show resolved Hide resolved

> Your schedule's name should be 3-63 characters long.
:::info Name Length
Your schedule's name should be 3-63 characters long.
:::

### From Apify Console
### Apify Console

In [Apify Console](https://console.apify.com/schedules), click on the **Schedules** button in the left-side menu, then click the **Create new** button.
In [Apify Console](https://console.apify.com/schedules), click on the **Schedules** in the navigation menu, then click the **Create new** button.

In the **Settings** tab, give your schedule a memorable name, add a description, and choose how often you would like your Actor or task to run using the [schedule setup tool](#schedule-setup).
Click on the name (by default it is _My Schedule_), there you can change the name of Schedule, add a description, as well as check it's _Unique name_ or _ID_.

![New schedule](./images/schedule-settings.png)
You can adjust how often your Actor or task runs using the [schedule setup tool](#schedule-setup). You can find it by clicking on **Schedule setup** tab.

![New schedule](./images/schedules-overview.png)

Next, you'll need to give the schedule something to run. This is where the Actor or task you prepared earlier comes in. Switch to the **Actors and Tasks** tab, and click the **Add [new]** button.

If you're scheduling an Actor run, you'll be able to specify the Actor's [input](./actors/running/input_and_output.md) and running options like
[build](./actors/development/builds_and_runs/builds.md),
timeout,
[memory](./actors/running/usage_and_resources.md).
The **timeout** value is specified in seconds; a value of **0** means there is no timeout, and the Actor runs until it finishes.
If you're scheduling an Actor run, you'll be able to specify the Actor's [input](./actors/running/input_and_output.md) and running options like [build](./actors/development/builds_and_runs/builds.md), timeout, [memory](./actors/running/usage_and_resources.md).
The **timeout** value is specified in seconds; a value of _0_ means there is no timeout, and the Actor runs until it finishes.

If you don't provide an input, then the Actor's default input is used. If you provide an input with some fields missing, the missing fields are filled in with values from the default input. If input options are not provided, the default options values are used.

![Add Actor to schedule](./images/schedule-actor-run.png)
![Add Actor to schedule](./images/schedules-actor-input.png)

If you're scheduling a task, just select the task you prepared earlier using the drop-down. If you need to override the task's input, you can pass it as a JSON object in the **Input JSON overrides** field.

![Add task to schedule](./images/schedule-add-tasks.png)
![Add task to schedule](./images/schedules-task-input.png)

To add more Actors or tasks, just repeat the process.

> You can add a maximum of 10 Actors and 10 tasks to each schedule.

Now, all you need to do is click **Save & activate** and let the scheduler take care of running your jobs on time.

For integrations, you can also add a [webhook](/platform/integrations/webhooks) to your tasks, which will notify you (or perform an action of your choice) every time the task runs.

### Via API
### Apify API
valekjo marked this conversation as resolved.
Show resolved Hide resolved

To create a new [schedule](/api/v2#/reference/schedules) using the Apify API, send a `POST` request to the [create schedule](/api/v2#/reference/schedules/schedules-collection/create-schedule) endpoint.

To create a new [schedule](/api/v2#/reference/schedules) using the [Apify API](/api/v2#), send a [POST request](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) to the [create schedule](/api/v2#/reference/schedules/schedules-collection/create-schedule) endpoint.
You can find your [secret API token](./integrations/index.mdx) in [Integrations](https://console.apify.com/account?tab=integrations) tab of your Apify account settings.

You can find your [secret API token](./integrations/index.mdx) in your Apify account's [Integrations](https://console.apify.com/account?tab=integrations) tab. When providing your API authentication token, we recommend using the request's `Authorization` header, rather than the URL ([more info](/api/v2#/introduction/authentication)).
:::caution API authentication recommendations
When providing your API authentication token, we recommend using the request's `Authorization` header, rather than the URL ([more info](/api/v2#/introduction/authentication)).
:::

In the POST request's payload should be a JSON object specifying the schedule's name, your [user ID](https://console.apify.com/account#/integrations), and the schedule's **actions**.
In the `POST` request's payload should be a JSON object specifying the schedule's name, your [user ID](https://console.apify.com/account#/integrations), and the schedule's _actions_.

The below JSON object creates a schedule which runs an SEO audit of the Apify domain once a month.
The following JSON object creates a schedule which runs an SEO audit of the Apify domain once a month.

```json
{
Expand All @@ -101,19 +106,19 @@ The below JSON object creates a schedule which runs an SEO audit of the Apify do
}
```

If the request is successful, you will receive a 201 [HTTP response code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) and a JSON object in the response body containing the details of your new schedule. If you receive an error (`4**` code), you will need to check your API token, user ID, or POST request body.
If the request is successful, you will receive a `201` [HTTP response code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) and a JSON object in the response body containing the details of your new schedule. If you receive an error (`4**` code), you will need to check your API token, user ID, or `POST` request body.

You can add multiple Actor and task runs to a schedule with a single POST request. Simply add another object with the run's details to the **actions** array in your POST request's payload object.
You can add multiple Actor and task runs to a schedule with a single `POST` request. Simply add another object with the run's details to the **actions** array in your `POST` request's payload object.

For more information, see the [schedules section](/api/v2#/reference/schedules/schedule-object/get-schedule) in the API documentation.
For more information, refer to the [schedules](/api/v2#/reference/schedules/schedule-object/get-schedule) section in our API documentation.

## Schedule setup

The schedule setup tool uses [cron expressions](https://en.wikipedia.org/wiki/Cron#CRON_expression) to specify run times. If you're familiar with how to use them and need a specific run schedule, you can dive right in. If not, don't worry - the setup tool has a visual custom schedule builder that provides a similar level of control as cron expressions, though it's not quite as powerful.

![Schedule setup tool](./images/schedule-setup.png)
![Schedule setup tool](./images/schedules-setup-tool.png)

The **Next runs** section at the bottom shows when the next five runs will be. You can use this live feedback to experiment until you find the correct configuration.
The **Next runs** section shows when the next run will be, if you click on **Show more** button it will expand and show you the next five runs. You can use this live feedback to experiment until you find the correct configuration.

You can find more information and examples of cron expressions on [crontab.guru](http://crontab.guru/). For additional and non-standard characters, see [this](https://en.wikipedia.org/wiki/Cron#CRON_expression) Wikipedia article.

Expand All @@ -122,7 +127,7 @@ You can find more information and examples of cron expressions on [crontab.guru]
A cron expression has the following structure:

| Position | Field | Values | Wildcards | Optional |
|----------|--------------|--------------------------------|-----------|----------|
|:----------|:--------------|:--------------------------------|:-----------|:----------|
| 1 | second | 0 - 59 | , - * / | yes |
| 2 | minute | 0 - 59 | , - * / | no |
| 3 | hour | 0 - 23 | , - * / | no |
Expand All @@ -136,19 +141,19 @@ The minimum interval between runs is 10 seconds; if your next run is scheduled s

### Examples of cron expressions

- `0 8 * * *` - every day at 8am.
- `0 0 * * 0` - every 7 days (at 00:00 on Sunday).
- `*/3 * * * *` - every 3rd minute.
- `0 0 1 */2 *` - every other month (at 00:00 on the first day of month, every 2nd month).
* `0 8 * * *` - every day at 8am.
* `0 0 * * 0` - every 7 days (at 00:00 on Sunday).
* `*/3 * * * *` - every 3rd minute.
* `0 0 1 */2 *` - every other month (at 00:00 on the first day of month, every 2nd month).

Additionally, you can use the following shortcut expressions:

- `@yearly` = `0 0 1 1 *` - once a year, on Jan 1st at midnight.
- `@monthly` = `0 0 1 * *` - once a month, on the 1st at midnight.
- `@weekly` = `0 0 * * 0` - once a week, on Sunday at midnight.
- `@daily` = `0 0 * * *` - run once a day, at midnight.
- `@hourly` = `0 * * * *` - on the hour, every hour.
* `@yearly` = `0 0 1 1 *` - once a year, on Jan 1st at midnight.
* `@monthly` = `0 0 1 * *` - once a month, on the 1st at midnight.
* `@weekly` = `0 0 * * 0` - once a week, on Sunday at midnight.
* `@daily` = `0 0 * * *` - run once a day, at midnight.
* `@hourly` = `0 * * * *` - on the hour, every hour.

## Sharing

You can invite other Apify users to view or modify your schedules with the [access rights](./collaboration/index.md) system. See the [full list of permissions](./collaboration/list_of_permissions.md).
You can invite other Apify users to view or modify your schedules with the [access rights](../platform/collaboration/index.md) system. See the [full list of permissions](../platform/collaboration/list_of_permissions.md).