-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdagster_carbon_job.py
More file actions
34 lines (22 loc) · 827 Bytes
/
Copy pathdagster_carbon_job.py
File metadata and controls
34 lines (22 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Example: carbon-aware Dagster job and sensor.
The gate op blocks the job until a target zone is clean; the sensor only requests
runs when the grid is already clean, so a heavy materialization lands on clean
energy either way.
pip install dagster
"""
from dagster import RunRequest, SkipReason, job, op, sensor
from integrations.dagster_carbon import carbon_gate, grid_is_clean
@op
def wait_for_green():
return carbon_gate(zones="auto:green", max_carbon=200)
@op
def retrain(_gate):
print("grid is clean — running the heavy job now")
@job
def carbon_aware_job():
retrain(wait_for_green())
@sensor(job=carbon_aware_job)
def only_when_green(_context):
if grid_is_clean(zones="auto:green", max_carbon=200):
return RunRequest(run_key=None)
return SkipReason("grid is not clean yet")