3838)
3939from sqlmesh .utils import to_snake_case
4040from sqlmesh .core .state_sync import StateSync
41+ from sqlmesh .utils import CorrelationId
4142from sqlmesh .utils .concurrency import NodeExecutionFailedError
4243from sqlmesh .utils .errors import PlanError , SQLMeshError
4344from sqlmesh .utils .dag import DAG
@@ -71,7 +72,7 @@ def __init__(
7172 self ,
7273 state_sync : StateSync ,
7374 snapshot_evaluator : SnapshotEvaluator ,
74- create_scheduler : t .Callable [[t .Iterable [Snapshot ]], Scheduler ],
75+ create_scheduler : t .Callable [[t .Iterable [Snapshot ], SnapshotEvaluator ], Scheduler ],
7576 default_catalog : t .Optional [str ],
7677 console : t .Optional [Console ] = None ,
7778 ):
@@ -88,6 +89,9 @@ def evaluate(
8889 circuit_breaker : t .Optional [t .Callable [[], bool ]] = None ,
8990 ) -> None :
9091 self ._circuit_breaker = circuit_breaker
92+ self .snapshot_evaluator = self .snapshot_evaluator .set_correlation_id (
93+ CorrelationId .from_plan_id (plan .plan_id )
94+ )
9195
9296 self .console .start_plan_evaluation (plan )
9397 analytics .collector .on_plan_apply_start (
@@ -106,6 +110,7 @@ def evaluate(
106110 else :
107111 analytics .collector .on_plan_apply_end (plan_id = plan .plan_id )
108112 finally :
113+ self .snapshot_evaluator .recycle ()
109114 self .console .stop_plan_evaluation ()
110115
111116 def _evaluate_stages (
@@ -228,7 +233,7 @@ def visit_backfill_stage(self, stage: stages.BackfillStage, plan: EvaluatablePla
228233 self .console .log_success ("SKIP: No model batches to execute" )
229234 return
230235
231- scheduler = self .create_scheduler (stage .all_snapshots .values ())
236+ scheduler = self .create_scheduler (stage .all_snapshots .values (), self . snapshot_evaluator )
232237 errors , _ = scheduler .run_merged_intervals (
233238 merged_intervals = stage .snapshot_to_intervals ,
234239 deployability_index = stage .deployability_index ,
@@ -249,7 +254,7 @@ def visit_audit_only_run_stage(
249254 return
250255
251256 # If there are any snapshots to be audited, we'll reuse the scheduler's internals to audit them
252- scheduler = self .create_scheduler (audit_snapshots )
257+ scheduler = self .create_scheduler (audit_snapshots , self . snapshot_evaluator )
253258 completion_status = scheduler .audit (
254259 plan .environment ,
255260 plan .start ,
0 commit comments