Script icon
Process icon
Set icon
Log icon

Carbon-Aware Batch Job Executor Companion Flow

Run a replaceable batch workload scheduled by Kestra and record its artifact, checksum, forecast context, and estimated, not measured, impact.

Categories
CoreInfrastructure

This is the companion flow for carbon-aware-batch-job-scheduler. The planner calls it immediately or creates a future execution with Subflow.scheduleDate. Keeping execution separate from planning means a deferred job is durable without leaving the planner or a worker sleeping for hours.

The included workload processes deterministic synthetic records, computes an aggregate and SHA-256 digest, and writes job-result.json. It is intentionally useful enough to verify execution while remaining safe to replace with dbt, Spark, Kubernetes, cloud batch, or model-training tasks.

How it works

  1. run_batch_workload (io.kestra.plugin.scripts.python.Script) processes records_to_process deterministic records in a Python container, writes a result artifact, and emits structured outputs.
  2. record_job_result (io.kestra.plugin.core.kv.Set) joins the real completion result with the planner's decision, deadline, forecast intensities, and estimated impact under carbon_job_result_<executor execution id>.
  3. summarize_completion writes an execution-log summary. Flow outputs return the artifact, record count, and checksum to immediate parent executions.
  4. record_executor_failure writes a durable FAILED marker under the same key when the workload errors, with the failed task id and its error lines from errorLogs(), so deferred failures remain discoverable even though their planner used wait: false.

Prerequisites and secrets

  • Kestra with the Python script plugin and Python 3 available on the worker.
  • No secrets or external services are required.
  • Import this flow into company.sustainability before the scheduler.

Inputs and outputs

The scheduler supplies all planning inputs. For a standalone smoke test, the defaults run 100,000 records and mark the reason as MANUAL_EXECUTION. The primary outputs are outputs.result_file, outputs.records_processed, and outputs.result_sha256; the KV audit key is carbon_job_result_<execution id>.

Production adaptation

Replace run_batch_workload with the real batch task or another subflow, keep the input contract, and add measured kWh to record_job_result. Do not relabel estimated_avoided_emissions_kg as measured savings unless energy telemetry is actually collected.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.