Skip to main content

Schedule API Reference

Schedule API Reference

Customer-hosted cloud features

note

Some features are only available on customer-hosted clouds. Reach out to support@anyscale.com for info.

Schedule CLI

anyscale schedule apply

Usage

anyscale schedule apply [OPTIONS]

Create or Update a Schedule

The schedule should be specified in a YAML config file.

Options

  • --config-file/-f: Path to a YAML config file to use for this schedule. Command-line flags will overwrite values read from the file.
  • --name/-n: Name of the schedule.

Examples

$ anyscale schedule apply -n my-schedule -f my-schedule.yaml
(anyscale +0.5s) Applying schedule with config ScheduleConfig(job_config=JobConfig(name='my-schedule', image_uri=None, compute_config=None, env_vars=None, py_modules=None, cloud=None, project=None, ray_version=None, job_queue_config=None), cron_expression='0 0 * * * *', timezone='UTC').
(anyscale +2.3s) Uploading local dir '.' to cloud storage.
(anyscale +3.7s) Including workspace-managed pip dependencies.
(anyscale +4.9s) Schedule 'my-schedule' submitted, ID: 'cronjob_vrjrbwcnfjjid7fsld3sfkn8jz'.

$ cat my-schedule.yaml
timezone: local
cron_expression: 0 0 * * * *
job_config:
name: my-job
entrypoint: python main.py
max_retries: 5

anyscale schedule list

Usage

anyscale schedule list [OPTIONS]

List Schedules

You can optionally filter schedules by name, project, cloud, or creator.

Options

  • --v2: [RECOMMENDED] Enable extended filtering options. Needs migration to match return values.
  • --name/-n: Filter by the name of the schedule.
  • --id/-i: Id of the schedule.
  • --project: The named Anyscale Project for the schedule. If not provided, the organization default will be used (or, if running in a workspace, the project of the workspace). Only with --v2 flag.
  • --cloud: The named Anyscale Cloud for the schedule. If not provided, the organization default will be used (or,if running in a workspace, the cloud of the workspace). Only with --v2 flag.
  • --creator-id: Filter by creator ID. Only with --v2 flag.
  • --max-items: Max total items (only with --no-interactive).
  • --page-size: Number of items per page (1-50). Only with --v2.
  • --json/-j: Output results as JSON. Only with --v2.
  • --interactive/--no-interactive: Enable interactive pagination. Only with --v2.
  • --include-all-users/--only-mine: Include schedules from all users. Only with --v2.

Examples

$ anyscale schedule list -n my-schedule
Output
+------------------------------------+-------------+---------------+-----------+-------------+------------------+------------+------------------+-----------------------+
| ID | NAME | DESCRIPTION | PROJECT | CRON | NEXT TRIGGER | TIMEZONE | CREATOR | LATEST EXECUTION ID |
|------------------------------------+-------------+---------------+-----------+-------------+------------------+------------+------------------+-----------------------|
| cronjob_vrjrbwcnfjjid7fsld3sfkn8jz | my-schedule | | default | 0 0 * * * * | 2 hours from now | UTC | doc@anyscale.com | |
+------------------------------------+-------------+---------------+-----------+-------------+------------------+------------+------------------+-----------------------+

anyscale schedule pause

Usage

anyscale schedule pause [OPTIONS]

Pause a Schedule.

You can pause a schedule by config file, name, or id.

To specify the schedule by name, use the --name flag. You can specify the cloud with --cloud and the project with --project.

To specify the schedule by id, use the --id flag.

To specify the schedule by config file, use --config-file. Ensure that name and optionally cloud and project are specified in the config file's job config.

Options

  • --config-file/-f: Path to a YAML config file to use for this schedule.
  • --name/-n: Name of the schedule.
  • --id/-i: Id of the schedule.
  • --cloud: The named Anyscale Cloud for the schedule. If not provided, the organization default will be used (or, if running in a workspace, the cloud of the workspace).
  • --project: Named project to use for the schedule. If not provided, the default project for the cloud will be used (or, if running in a workspace, the project of the workspace).

Examples

$ anyscale schedule pause -n my-schedule
(anyscale +3.6s) Set schedule 'my-schedule' to state DISABLED

anyscale schedule resume

Usage

anyscale schedule resume [OPTIONS]

Resume a Schedule

You can resume a schedule by config file, name, or id.

To specify the schedule by name, use the --name flag. You can specify the cloud with --cloud and the project with --project.

To specify the schedule by id, use the --id flag.

To specify the schedule by config file, use --config-file. Ensure that name and optionally cloud and project are specified in the config file's job config.

Options

  • --config-file/-f: Path to a YAML config file to use for this schedule.
  • --name/-n: Name of the schedule.
  • --id/-i: Id of the schedule.
  • --cloud: The named Anyscale Cloud for the schedule. If not provided, the organization default will be used (or, if running in a workspace, the cloud of the workspace).
  • --project: Named project to use for the schedule. If not provided, the default project for the cloud will be used (or, if running in a workspace, the project of the workspace).

Examples

$ anyscale schedule resume -n my-schedule
(anyscale +4.1s) Set schedule 'my-schedule' to state ENABLED

anyscale schedule status

Usage

anyscale schedule status [OPTIONS]

Query the status of a Schedule.

You can query the status of a schedule by config file, name, or id.

To specify the schedule by name, use the --name flag. You can specify the cloud with --cloud and the project with --project.

To specify the schedule by id, use the --id flag.

To specify the schedule by config file, use --config-file. Ensure that name and optionally cloud and project are specified in the config file's job config.

Options

  • --config-file/-f: Path to a YAML config file to use for this schedule.
  • --name/-n: Name of the schedule.
  • --id/-i: Id of the schedule.
  • --cloud: The named Anyscale Cloud for the schedule. If not provided, the organization default will be used (or, if running in a workspace, the cloud of the workspace).
  • --project: Named project to use for the schedule. If not provided, the default project for the cloud will be used (or, if running in a workspace, the project of the workspace).
  • --json/-j: Output the status in a structured JSON format.
  • --verbose/-v: Include verbose details in the status.

Examples

$ anyscale schedule status -n my-schedule
id: cronjob_vrjrbwcnfjjid7fsld3sfkn8jz
name: my-schedule
state: ENABLED

anyscale schedule run

Usage

anyscale schedule run [OPTIONS]

Manually run a Schedule

This function takes an existing schedule and runs it now. You can specify the schedule by name or id. You can also pass in a YAML file as a convinience. This is equivalent to passing in the name specified in the YAML file. IMPORTANT: if you pass in a YAML definition that differs from the Schedule defition, the Schedule will NOT be updated. Please use the anyscale schedule apply command to update the configuration of your schedule or use the anyscale job submit command to submit a one off job that is not a part of a schedule.

Options

  • --config-file/-f: Path to a YAML config file to use for this schedule.
  • --name/-n: Name of the schedule.
  • --id/-i: Id of the schedule.
  • --cloud: The named Anyscale Cloud for the schedule. If not provided, the organization default will be used (or, if running in a workspace, the cloud of the workspace).
  • --project: Named project to use for the schedule. If not provided, the default project for the cloud will be used (or, if running in a workspace, the project of the workspace).

Examples

$ anyscale schedule run -n my-schedule
(anyscale +2.5s) Triggered job for schedule 'my-schedule'.

anyscale schedule url

Usage

anyscale schedule url [OPTIONS] [SCHEDULE_CONFIG_FILE]

Get a Schedule URL

This function accepts 1 argument, a path to a YAML config file that defines this schedule. You can also specify the schedule by name or id.

Options

  • --name/-n: Name of the schedule.
  • --id/-i: Id of the schedule.
  • --v2: Use new SDK-based implementation
  • --cloud: Cloud name (required with --name in v2 mode)
  • --project: Project name (required with --name in v2 mode)

Examples

$ anyscale schedule url -n my-schedule
Output
(anyscale +2.3s) View your schedule at https://console.anyscale.com/scheduled-jobs/cronjob_7zj

anyscale schedule delete

Usage

anyscale schedule delete [OPTIONS]

Delete a Schedule.

If the schedule is active, it will be automatically paused before deletion. The schedule must have no active triggered jobs.

To specify the schedule by id, use the --id flag.

To specify the schedule by name, use the --name flag along with --cloud and --project.

Options

  • --name/-n: Name of the schedule.
  • --id/-i: Id of the schedule.
  • --cloud: The named Anyscale Cloud for the schedule (required with --name).
  • --project: Named project for the schedule (required with --name).

Examples

$ anyscale schedule delete --id cronjob_vrjrbwcnfjjid7fsld3sfkn8jz
(anyscale +2.3s) Schedule 'my-schedule' deleted.

$ anyscale schedule delete --name my-schedule --cloud my-cloud --project my-project
(anyscale +2.5s) Schedule 'my-schedule' deleted.

Schedule SDK

anyscale.schedule.apply

Apply or update a schedule.

Returns the id of the schedule.

Arguments

Returns: str

Examples

import anyscale
from anyscale.job.models import JobConfig
from anyscale.schedule.models import ScheduleConfig

anyscale.schedule.apply(
ScheduleConfig(
cron_expression="0 0 * * * *",
job_config=JobConfig(
name="my-job",
entrypoint="python main.py",
working_dir=".",
)
)
)

anyscale.schedule.set_state

Set the state of a schedule.

Returns the id of the schedule.

Arguments

  • id (str | None) = None: The id of the schedule.
  • name (str | None) = None: The name of the schedule.
  • cloud (str | None) = None: The Anyscale Cloud to run this workload on. If not provided, the organization default will be used (or, if running in a workspace, the cloud of the workspace).
  • project (str | None) = None: Named project to use for the job. If not provided, the default project for the cloud will be used (or, if running in a workspace, the project of the workspace).
  • state (ScheduleState): The state to set the schedule to.

Returns: str

Examples

import anyscale
from anyscale.schedule.models import ScheduleState

anyscale.schedule.set_state(
id="my=schedule-id",
state=ScheduleState.DISABLED,
)

anyscale.schedule.status

Return the status of the schedule.

Arguments

  • id (str | None) = None: The id of the schedule.
  • name (str | None) = None: The name of the schedule.
  • cloud (str | None) = None: The Anyscale Cloud to run this workload on. If not provided, the organization default will be used (or, if running in a workspace, the cloud of the workspace).
  • project (str | None) = None: Named project to use for the job. If not provided, the default project for the cloud will be used (or, if running in a workspace, the project of the workspace).

Returns: ScheduleStatus

Examples

import anyscale
anyscale.schedule.status(id="cronjob_yt389jvskwht9k2ygx7rj6iz62")

anyscale.schedule.trigger

Trigger the execution of the schedule.

Arguments

  • id (str | None) = None: The id of the schedule.
  • name (str | None) = None: The name of the schedule.
  • cloud (str | None) = None: The Anyscale Cloud to run this workload on. If not provided, the organization default will be used (or, if running in a workspace, the cloud of the workspace).
  • project (str | None) = None: Named project to use for the job. If not provided, the default project for the cloud will be used (or, if running in a workspace, the project of the workspace).

Returns: str

Examples

import anyscale
anyscale.schedule.trigger(id="cronjob_yt389jvskwht9k2ygx7rj6iz62")

anyscale.schedule.list

List schedules with filtering and pagination.

Returns a ResultIterator that lazily fetches pages of schedules.

Arguments

  • name (str | None) = None: Filter by schedule name.
  • schedule_id (str | None) = None: Fetch a specific schedule by ID.
  • project (str | None) = None: Filter by project name.
  • cloud (str | None) = None: Filter by cloud name.
  • creator_id (str | None) = None: Filter by creator ID.
  • include_all_users (bool) = False: Include schedules from all users.
  • page_size (int | None) = None: Number of items per page.
  • max_items (int | None) = None: Maximum total items to return.

Returns: ResultIterator[ScheduleStatus]

Examples

import anyscale
from anyscale.schedule.models import ScheduleStatus

# List all schedules
for schedule in anyscale.schedule.list(max_items=10):
print(f"{schedule.name}: {schedule.state}")

# Filter by project
schedules = list(anyscale.schedule.list(project="my-project"))

anyscale.schedule.url

Get the web UI URL for a schedule.

Arguments

  • id (str | None) = None: The schedule ID.
  • name (str | None) = None: The schedule name (requires cloud and project).
  • cloud (str | None) = None: Cloud name (required with name).
  • project (str | None) = None: Project name (required with name).

Returns: str

Examples

import anyscale

# Get URL by ID
url = anyscale.schedule.url(id="cronjob_xxx")
print(url)

# Get URL by name
url = anyscale.schedule.url(name="my-schedule", cloud="my-cloud", project="my-project")
print(url)

anyscale.schedule.delete

Delete a schedule.

If the schedule is active, it will be automatically paused before deletion. The schedule must have no active triggered jobs. Returns the ID of the deleted schedule.

Arguments

  • id (str | None) = None: The schedule ID.
  • name (str | None) = None: The schedule name (requires cloud and project).
  • cloud (str | None) = None: Cloud name (required with name).
  • project (str | None) = None: Project name (required with name).

Returns: str

Examples

import anyscale

# Delete by ID
anyscale.schedule.delete(id="cronjob_xxx")

# Delete by name
anyscale.schedule.delete(name="my-schedule", cloud="my-cloud", project="my-project")

Schedule Models

ScheduleConfig

Configuration options for a schedule.

Fields

  • job_config (Dict | JobConfig): Configuration of the job.
  • cron_expression (str): A cron expression to define the frequency at which to run this cron job, for example '0 0 * * *' is a cron expression that means 'run at midnight'. Visit crontab.guru to construct a precise cron_expression.
  • timezone (str): The timezone in which to interpret the cron_expression. Default is Universal time (UTC). You can specify 'local' to use the local timezone

Python Methods

def __init__(self, **fields) -> ScheduleConfig
"""Construct a model with the provided field values set."""

def options(self, **fields) -> ScheduleConfig
"""Return a copy of the model with the provided field values overwritten."""

def to_dict(self) -> Dict[str, Any]
"""Return a dictionary representation of the model."""

Examples

timezone: local
cron_expression: 0 0 * * * *
job_config:
name: my-schedule-job
entrypoint: python main.py
max_retries: 5

ScheduleState

Current state of a schedule.

Values

  • ENABLED: The schedule is enabled. Jobs will be started according to this jobs cron expression.
  • DISABLED: The schedule is disabled. No jobs will be started until the schedule is reenabled.

ScheduleStatus

Current status of a schedule.

Fields

  • config (ScheduleConfig): Configuration of the schedule.
  • id (str): Unique ID of the schedule (generated when the schedule is first submitted).
  • name (str): Name of the schedule.
  • state (str | ScheduleState): Current state of the schedule.

Python Methods

def to_dict(self) -> Dict[str, Any]
"""Return a dictionary representation of the model."""

Examples

import anyscale
from anyscale.schedule.models import ScheduleStatus
status: ScheduleStatus = anyscale.schedule.status(name="my-schedule")