Branch 1: failed run journal + bisect Infeasible + granulární relaxace (bez vypnutí evening push)
This commit is contained in:
14
db/migration/V084__planning_run_failed_status.sql
Normal file
14
db/migration/V084__planning_run_failed_status.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Journal neúspěšných běhů plánovače (Solver: Infeasible po celém retry řetězci).
|
||||
|
||||
alter table ems.planning_run
|
||||
add column if not exists error_text text;
|
||||
|
||||
comment on column ems.planning_run.error_text is
|
||||
'Chybová zpráva u status=failed (typicky Solver: Infeasible); aktivní plán se nemění.';
|
||||
|
||||
comment on column ems.planning_run.status is
|
||||
'Stav plánu: draft, approved, active, superseded, comparison (shadow běh), failed (solver selhal).';
|
||||
|
||||
create index if not exists idx_planning_run_site_failed
|
||||
on ems.planning_run (site_id, created_at desc)
|
||||
where status = 'failed';
|
||||
50
db/routines/R__091_fn_planning_run_fail.sql
Normal file
50
db/routines/R__091_fn_planning_run_fail.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
-- neúspěšný běh plánovače bez aktivace a bez supersede aktivního plánu
|
||||
|
||||
create or replace function ems.fn_planning_run_fail(
|
||||
p_site_id int,
|
||||
p_horizon_start timestamptz,
|
||||
p_horizon_end timestamptz,
|
||||
p_run_meta jsonb
|
||||
)
|
||||
returns int
|
||||
language plpgsql
|
||||
as $fn$
|
||||
declare
|
||||
v_run_id int;
|
||||
begin
|
||||
insert into ems.planning_run (
|
||||
site_id, horizon_start, horizon_end, status,
|
||||
run_type, triggered_by, replan_from,
|
||||
soc_at_replan_wh, solver_duration_ms, forecast_correction_factor,
|
||||
solver_params, error_text
|
||||
) values (
|
||||
p_site_id,
|
||||
p_horizon_start,
|
||||
p_horizon_end,
|
||||
'failed',
|
||||
nullif(trim(p_run_meta->>'run_type'), ''),
|
||||
nullif(trim(p_run_meta->>'triggered_by'), ''),
|
||||
case
|
||||
when p_run_meta ? 'replan_from' and (p_run_meta->>'replan_from') is not null
|
||||
and (p_run_meta->>'replan_from') <> 'null'
|
||||
then (p_run_meta->>'replan_from')::timestamptz
|
||||
else null::timestamptz
|
||||
end,
|
||||
(p_run_meta->>'soc_at_replan_wh')::numeric,
|
||||
coalesce((p_run_meta->>'solver_duration_ms')::int, 0),
|
||||
coalesce((p_run_meta->>'forecast_correction_factor')::numeric, 1.0),
|
||||
case
|
||||
when p_run_meta ? 'solver_params' and jsonb_typeof(p_run_meta->'solver_params') = 'object'
|
||||
then p_run_meta->'solver_params'
|
||||
else null::jsonb
|
||||
end,
|
||||
nullif(trim(p_run_meta->>'error_text'), '')
|
||||
)
|
||||
returning id into v_run_id;
|
||||
|
||||
return v_run_id;
|
||||
end;
|
||||
$fn$;
|
||||
|
||||
comment on function ems.fn_planning_run_fail is
|
||||
'Uloží planning_run se statusem failed; neaktivuje plán a nesupersededuje active.';
|
||||
Reference in New Issue
Block a user