Developer docs / AI Fabric tutorials
Nightly batch job
- Cron
- Volume
- Image DSL
Take it for a spin
The whole program in one file, ready to run.
import bladekit
app = bladekit.app("nightly-batch")
output_vol = bladekit.Volume.from_name("nightly-results", create_if_missing=True)
image = (
bladekit.Image.debian_slim(python_version="3.12")
.pip_install("polars", "pyarrow", "httpx")
)
@app.function(
image=image,
cpu=8,
memory=16384,
timeout=3600,
volumes={"/results": output_vol},
schedule=bladekit.Cron("0 3 * * *"), # 03:00 UTC every day
retries=1,
)
def nightly_job() -> None:
import polars as pl
from datetime import datetime, timezone
today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
print(f"Starting nightly batch for {today}")
# Example: aggregate the day's data (swap this synthetic frame for a
# real ingestion source, e.g. an httpx.get() call, in production).
df = pl.DataFrame(
{
"region": ["us-east", "us-west", "eu-west", "us-east", "eu-west"],
"revenue": [120.5, 98.2, 75.0, 40.1, 60.3],
}
)
summary = df.group_by("region").agg(pl.col("revenue").sum())
summary.write_parquet(f"/results/{today}-summary.parquet")
output_vol.commit() # persist writes so other functions can read them
print(f"Saved {len(summary)} regions to Volume.")Run it
- Deploy:
blade deploy nightly_batch.py. - The job runs every night at 03:00 UTC. Go to the Crons page to see the schedule and last run status.
- Results are saved to the
nightly-resultsVolume. Mount it in another function to query them. retries=1means if tonight's run fails, AI Fabric tries once more before marking it failed.
Concepts used: Deployment, Run