77
88namespace DataMachineCode \Cleanup ;
99
10+ use DataMachineCode \Support \SystemTaskDrainability ;
11+
1012defined ('ABSPATH ' ) || exit;
1113
1214class DataMachineJobCleanupRunEvidenceStore implements CleanupRunEvidenceStoreInterface {
@@ -126,19 +128,20 @@ private function aggregate_cleanup_child_jobs( array $child_jobs ): array {
126128 'remaining_safely_removable_worktrees ' => 0 ,
127129 ),
128130 'children ' => array (
129- 'batch_job_ids ' => array (),
130- 'chunk_job_ids ' => array (),
131- 'pending_job_ids ' => array (),
132- 'processing_job_ids ' => array (),
133- 'failed_job_ids ' => array (),
134- 'processing ' => 0 ,
135- 'completed ' => 0 ,
136- 'failed ' => 0 ,
137- 'skipped ' => 0 ,
138- 'running ' => 0 ,
139- 'total ' => 0 ,
140- 'statuses ' => array (),
141- 'job_ids ' => array (),
131+ 'batch_job_ids ' => array (),
132+ 'chunk_job_ids ' => array (),
133+ 'pending_job_ids ' => array (),
134+ 'pending_without_drainable_action_job_ids ' => array (),
135+ 'processing_job_ids ' => array (),
136+ 'failed_job_ids ' => array (),
137+ 'processing ' => 0 ,
138+ 'completed ' => 0 ,
139+ 'failed ' => 0 ,
140+ 'skipped ' => 0 ,
141+ 'running ' => 0 ,
142+ 'total ' => 0 ,
143+ 'statuses ' => array (),
144+ 'job_ids ' => array (),
142145 ),
143146 );
144147
@@ -162,6 +165,9 @@ private function aggregate_cleanup_child_jobs( array $child_jobs ): array {
162165 $ summary ['children ' ]['job_ids ' ][] = $ child_job_id ;
163166 if ( 'pending ' === $ status ) {
164167 $ summary ['children ' ]['pending_job_ids ' ][] = $ child_job_id ;
168+ if ( ! SystemTaskDrainability::job_has_execute_step_action ($ child_job_id ) ) {
169+ $ summary ['children ' ]['pending_without_drainable_action_job_ids ' ][] = $ child_job_id ;
170+ }
165171 } elseif ( 'processing ' === $ status && ! $ idle_wrapper ) {
166172 $ summary ['children ' ]['processing_job_ids ' ][] = $ child_job_id ;
167173 } elseif ( str_starts_with ($ status , 'failed ' ) ) {
@@ -204,11 +210,12 @@ private function aggregate_cleanup_child_jobs( array $child_jobs ): array {
204210 $ summary ['cleanup_items ' ]['freed_human ' ] = $ this ->format_bytes ($ summary ['cleanup_items ' ]['bytes_reclaimed ' ]);
205211 $ summary ['children ' ]['batch_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['batch_job_ids ' ]));
206212 $ summary ['children ' ]['chunk_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['chunk_job_ids ' ]));
207- $ summary ['children ' ]['pending_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['pending_job_ids ' ]));
208- $ summary ['children ' ]['processing_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['processing_job_ids ' ]));
209- $ summary ['children ' ]['failed_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['failed_job_ids ' ]));
210- $ summary ['children ' ]['job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['job_ids ' ]));
211- $ summary ['children ' ]['running ' ] = (int ) $ summary ['children ' ]['processing ' ];
213+ $ summary ['children ' ]['pending_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['pending_job_ids ' ]));
214+ $ summary ['children ' ]['pending_without_drainable_action_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['pending_without_drainable_action_job_ids ' ]));
215+ $ summary ['children ' ]['processing_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['processing_job_ids ' ]));
216+ $ summary ['children ' ]['failed_job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['failed_job_ids ' ]));
217+ $ summary ['children ' ]['job_ids ' ] = array_values (array_unique ($ summary ['children ' ]['job_ids ' ]));
218+ $ summary ['children ' ]['running ' ] = (int ) $ summary ['children ' ]['processing ' ];
212219
213220 return $ summary ;
214221 }
@@ -224,6 +231,7 @@ private function summarize_cleanup_children( array $children ): array {
224231 $ batch_ids = (array ) ( $ children ['batch_job_ids ' ] ?? array () );
225232 $ chunk_ids = (array ) ( $ children ['chunk_job_ids ' ] ?? array () );
226233 $ pending = (array ) ( $ children ['pending_job_ids ' ] ?? array () );
234+ $ undrainable = (array ) ( $ children ['pending_without_drainable_action_job_ids ' ] ?? array () );
227235 $ processing = (array ) ( $ children ['processing_job_ids ' ] ?? array () );
228236
229237 return array (
@@ -238,6 +246,7 @@ private function summarize_cleanup_children( array $children ): array {
238246 'chunk_total ' => count ($ chunk_ids ),
239247 'failed_job_ids ' => (array ) ( $ children ['failed_job_ids ' ] ?? array () ),
240248 'pending_job_ids ' => array_slice ($ pending , 0 , $ limit ),
249+ 'pending_without_drainable_action_job_ids ' => array_slice ($ undrainable , 0 , $ limit ),
241250 'processing_job_ids ' => array_slice ($ processing , 0 , $ limit ),
242251 'pending_truncated ' => count ($ pending ) > $ limit ,
243252 'processing_truncated ' => count ($ processing ) > $ limit ,
@@ -277,13 +286,24 @@ private function cleanup_run_drain_summary( int $job_id, string $state, array $c
277286 if ( array () !== $ active_child_ids ) {
278287 $ commands ['active_children ' ] = sprintf ('studio wp datamachine drain --job-id=%s ' , implode (', ' , $ active_child_ids ));
279288 }
289+ $ undrainable_child_ids = array_values (
290+ array_unique (
291+ array_filter (
292+ array_map ('intval ' , (array ) ( $ children ['pending_without_drainable_action_job_ids ' ] ?? array () ))
293+ )
294+ )
295+ );
296+ if ( array () !== $ undrainable_child_ids ) {
297+ $ commands ['repair_undrainable_children ' ] = sprintf ('studio wp datamachine-code workspace cleanup resume %s --format=json ' , $ run_id );
298+ }
280299
281300 return array (
282301 'needed ' => in_array ($ state , array ( 'running ' , 'waiting_on_children ' ), true ),
283302 'commands ' => $ commands ,
284- 'active_child_job_ids ' => $ active_child_ids ,
285- 'bytes_reclaimed ' => (int ) ( $ cleanup_items ['bytes_reclaimed ' ] ?? 0 ),
286- 'freed_human ' => (string ) ( $ cleanup_items ['freed_human ' ] ?? $ this ->format_bytes (0 ) ),
303+ 'active_child_job_ids ' => $ active_child_ids ,
304+ 'undrainable_child_job_ids ' => $ undrainable_child_ids ,
305+ 'bytes_reclaimed ' => (int ) ( $ cleanup_items ['bytes_reclaimed ' ] ?? 0 ),
306+ 'freed_human ' => (string ) ( $ cleanup_items ['freed_human ' ] ?? $ this ->format_bytes (0 ) ),
287307 );
288308 }
289309
0 commit comments