@@ -171,14 +171,15 @@ handle_result(
171171 # prg_worker_state {
172172 ns_id = NsId ,
173173 ns_opts = #{storage := StorageOpts } = NsOpts ,
174- process = #{process_id := ProcessId } = Process ,
174+ process = #{process_id := ProcessId , status : = OldStatus } = Process ,
175175 sidecar_pid = Pid
176176 } = State
177177) ->
178178 Now = erlang :system_time (second ),
179- ProcessUpdated = update_process (
180- maps :without ([detail , corrupted_by ], Process #{status => <<" running" >>}), Result
181- ),
179+ #{status := NewStatus } =
180+ ProcessUpdated = update_process (
181+ maps :without ([detail , corrupted_by ], Process #{status => <<" running" >>}), Result
182+ ),
182183 Response = response (maps :get (response , Result , undefined )),
183184 TaskResult = #{
184185 task_id => TaskId ,
@@ -196,7 +197,7 @@ handle_result(
196197 attempts_count => 0
197198 },
198199 ok = prg_worker_sidecar :lifecycle_sink (
199- Pid , Deadline , NsOpts , extract_task_type (TaskHeader ), ProcessId
200+ Pid , Deadline , NsOpts , lifecycle_event (TaskHeader , OldStatus , NewStatus ), ProcessId
200201 ),
201202 ok = prg_worker_sidecar :event_sink (Pid , Deadline , NsOpts , ProcessId , Events ),
202203 SaveResult = prg_worker_sidecar :complete_and_continue (
@@ -249,17 +250,18 @@ handle_result(
249250 # prg_worker_state {
250251 ns_id = NsId ,
251252 ns_opts = #{storage := StorageOpts } = NsOpts ,
252- process = #{process_id := ProcessId } = Process ,
253+ process = #{process_id := ProcessId , status : = OldStatus } = Process ,
253254 sidecar_pid = Pid
254255 } = State
255256) ->
257+ #{status := NewStatus } =
258+ ProcessUpdated = update_process (
259+ maps :without ([detail , corrupted_by ], Process #{status => <<" running" >>}), Result
260+ ),
256261 ok = prg_worker_sidecar :lifecycle_sink (
257- Pid , Deadline , NsOpts , extract_task_type (TaskHeader ), ProcessId
262+ Pid , Deadline , NsOpts , lifecycle_event (TaskHeader , OldStatus , NewStatus ), ProcessId
258263 ),
259264 ok = prg_worker_sidecar :event_sink (Pid , Deadline , NsOpts , ProcessId , Events ),
260- ProcessUpdated = update_process (
261- maps :without ([detail , corrupted_by ], Process #{status => <<" running" >>}), Result
262- ),
263265 Response = response (maps :get (response , Result , undefined )),
264266 TaskResult = #{
265267 task_id => TaskId ,
@@ -303,7 +305,7 @@ handle_result(
303305) ->
304306 Now = erlang :system_time (second ),
305307 ok = prg_worker_sidecar :lifecycle_sink (
306- Pid , Deadline , NsOpts , extract_task_type ( TaskHeader ) , ProcessId
308+ Pid , Deadline , NsOpts , repair , ProcessId
307309 ),
308310 ok = prg_worker_sidecar :event_sink (Pid , Deadline , NsOpts , ProcessId , Events ),
309311 ProcessUpdated = update_process (
@@ -368,17 +370,18 @@ handle_result(
368370 # prg_worker_state {
369371 ns_id = NsId ,
370372 ns_opts = #{storage := StorageOpts } = NsOpts ,
371- process = #{process_id := ProcessId } = Process ,
373+ process = #{process_id := ProcessId , status : = OldStatus } = Process ,
372374 sidecar_pid = Pid
373375 } = State
374376) ->
377+ #{status := NewStatus } =
378+ ProcessUpdated = update_process (
379+ maps :without ([detail , corrupted_by ], Process #{status => <<" running" >>}), Result
380+ ),
375381 ok = prg_worker_sidecar :lifecycle_sink (
376- Pid , Deadline , NsOpts , extract_task_type (TaskHeader ), ProcessId
382+ Pid , Deadline , NsOpts , lifecycle_event (TaskHeader , OldStatus , NewStatus ), ProcessId
377383 ),
378384 ok = prg_worker_sidecar :event_sink (Pid , Deadline , NsOpts , ProcessId , Events ),
379- ProcessUpdated = update_process (
380- maps :without ([detail , corrupted_by ], Process #{status => <<" running" >>}), Result
381- ),
382385 Response = response (maps :get (response , Result , undefined )),
383386 TaskResult = #{
384387 task_id => TaskId ,
@@ -601,3 +604,10 @@ last_event_id([]) ->
601604last_event_id (History ) ->
602605 [#{event_id := Id } | _ ] = lists :reverse (History ),
603606 Id .
607+
608+ lifecycle_event ({timeout , _ }, <<" error" >>, <<" running" >>) ->
609+ repair ;
610+ lifecycle_event ({timeout , _ }, _ , _ ) ->
611+ timeout ;
612+ lifecycle_event ({TaskType , _ }, _ , _ ) ->
613+ TaskType .
0 commit comments