Skip to main content

Schedules

danger

Schedules are an feature in alpha release. Please reach out to customer support to enable this feature in your account.

Schedules run Production Jobs at a specified cadence, enabling you to automatically run a training or inference workload each day. Schedules extend the Jobs YAML with an additional schedule config. To create a schedule from an existing job, add the schedule config as shown below.

job.yaml
name: nightly
... # your Job config
schedule:
cron_expression: 0 0 * * * # A cron expression
timezone: local # The timezone in which to interpret the cron expression

Then run

anyscale schedule create job.yaml  # Run the job every night

To view the full Production Job YAML spec, see the Production Jobs reference. For more information about Cron Expressions, view the reference

The rest of this walkthrough will cover a more comprehensive example.

Setup your environment

Install the latest Ray and Anyscale

pip install ray
pip install -U anyscale

Clone the Anyscale Examples Repo.

git clone https://github.com/anyscale/docs_examples.git anyscale_doc_examples
cd anyscale_doc_examples

Creating your first Schedule

info

Schedules are uniquely identified inside of a project by their name. If you try to create 2 schedules with the same name, this will update the first schedule instead of creating a new one.

In this example, we create a simple schedule that runs a Production Job every 10 minutes to say "hello world".

anyscale schedule create scheduled_job.yaml

Now let's view the created Schedule.

schedule table

$ anyscale schedule list
+----------------------------------+---------------+----------------------+-----------+--------------+--------------------+---------------------+-------------------+-----------------------+
| ID | NAME | DESCRIPTION | PROJECT | CRON | NEXT TRIGGER | TIMEZONE | CREATOR | LATEST EXECUTION ID |
|----------------------------------+---------------+----------------------+-----------+--------------+--------------------+---------------------+-------------------+-----------------------|
| cronjob_KwXNBUBnHVW1RhRafvNFdmVq | schedule-demo | Run every 10 minutes | default | */10 * * * * | 8 minutes from now | America/Los_Angeles | demo@anyscale.com | |
+----------------------------------+---------------+----------------------+-----------+--------------+--------------------+---------------------+-------------------+-----------------------+

If you visit the URL printed out of the CLI, you should see a new Schedule in the UI.

Manually run the schedule

If you don't want to wait for the next trigger time, you can manually run the schedule by name.

anyscale schedule run -n schedule-demo

You should see a Production Job kick off, and a link to the Production Job.

Pause and Resume the schedule

Let's pause this schedule so we don't keep spitting out Jobs.

anyscale schedule pause -n schedule-demo

Here is how to resume the schedule

anyscale schedule resume -n schedule-demo

Update the schedule

Let's instead update the schedule to run at 9am each morning.

To update the Schedule, use the anyscale schedule update command.

name: schedule-demo
description: Run at 9am
entrypoint: python hello_world.py
runtime_env:
working_dir: "https://github.com/anyscale/docs_examples/archive/refs/heads/main.zip"
schedule:
- cron_expression: "*/10 * * * *"
+ cron_expression: "0 9 * * *"
timezone: local
schedule table

$ anyscale schedule list
+----------------------------------+---------------+----------------------+-----------+--------------+--------------------+---------------------+-------------------+-----------------------+
| ID | NAME | DESCRIPTION | PROJECT | CRON | NEXT TRIGGER | TIMEZONE | CREATOR | LATEST EXECUTION ID |
|----------------------------------+---------------+----------------------+-----------+--------------+--------------------+---------------------+-------------------+-----------------------|
| cronjob_KwXNBUBnHVW1RhRafvNFdmVq | schedule-demo | Run at 9am | default | 0 9 * * * | 8 hours from now | America/Los_Angeles | demo@anyscale.com | |
+----------------------------------+---------------+----------------------+-----------+--------------+--------------------+---------------------+-------------------+-----------------------+
note

You can update any field, except for the name and the project. You can also update the Cluster Environment or the description for example.