Web Endpoints
Scheduled Job
A short guide on using Beam to run functions on a schedule
Beam apps can be run on a schedule with the schedule
decorator.
from beam import App, Volume, Output
app = App(
name="my-app",
volumes=[
Volume(name="files", path="./files"),
],
)
@app.schedule(when="every 5m")
def handler():
return
schedule
supports cron and string expressions. You can use Crontab to help generate expressions.
Scheduled Jobs are run based on the UTC timezone.
Parameter | Required | Description |
---|---|---|
when | Yes | The scheduling time or interval for the task execution. It can be a cron or string expressions. You can use Crontab to help generate expressions. |
runtime | No | The runtime environment to execute the scheduled task. Default is None. |
outputs | No | A list of outputs for handling the results of the scheduled task. Default is []. |
callback_url | No | A URL where task execution status updates will be sent. If provided, the system will make a single POST request to this URL with status updates for each task. Default is None. |
Testing your function
You can create a one-off run of your function with beam run
:
beam run app.py:your_function
You can also pass in JSON payloads by using the -d
flag:
beam run app.py:your_function -d '{"your_key": "your_value"}'
Deploying a Scheduled Job
To deploy the app, enter your shell and run this command from the working directory:
beam deploy app.py:your_function
After running this command, you’ll see some logs in the console that show the progress of your deployment.
Cron Expression Cheatsheet
Beam supports standard cron expressions. Here are a few examples:
Schedule | Syntax |
---|---|
Every minute | */1 * * * * |
Every day at mightnight | 0 0 * * * |
10:15am, daily | 0 15 10 ? * * |
2:10 p.m. and at 2:44 p.m. every Wednesday in the month of March | 0 10,44 14 ? 3 WED |
String Expression Cheatsheet
You can also write expressions using a friendlier human-readable syntax, for intervals up to 1 hour.
Schedule | Syntax |
---|---|
Every 1 second | every 1s |
Every 5 minutes | every 5m |
Every 1 hour | every 1h |
Further Reading
Was this page helpful?