← All examples

Pipelines & crons

Run a pipeline every night

A cron expression on a function. Every night the whole prep, train, evaluate chain runs unattended and its outputs land on a volume; the dashboard shows each run as a task.

Whatever the scheduled function asks for; the stages it calls run on their own containers.

How it works

  1. 1@cron(when="0 2 * * *") deploys a function that the controlplane invokes on the cron (UTC).
  2. 2Inside it, call other functions with .remote() and .map(); each stage is its own task and container.
  3. 3Outputs go to a volume; a versioned folder per run keeps yesterday's results next to today's.
  4. 4levers9 deployment list shows the cron; stop it to pause, start to resume.

The code

demo/cron/app.py
from levers9 import cron

@cron(when="0 2 * * *", cpu=1, memory="512Mi")
def nightly():
    data = prep.remote()
    models = list(train.map(configs))
    package.remote(evaluate.remote(models)["best"])
run it
cd demo/cron
levers9 deploy app.py:nightly --name nightly

Where to go next

Related