Skip to content

Commit 425018a

Browse files
authored
Merge pull request #860 from Extra-Chill/fix/batch-child-job-status
Fix batch child jobs created as 'processing' instead of 'pending'
2 parents 1e5ef50 + f17dcbf commit 425018a

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

inc/Abilities/Engine/ExecuteStepAbility.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ public function execute( array $input ): array {
102102
$job_id = (int) ( $input['job_id'] ?? 0 );
103103
$flow_step_id = (string) ( $input['flow_step_id'] ?? '' );
104104

105+
// Transition job to 'processing' now that Action Scheduler is actually
106+
// executing it. For parent jobs this is a no-op (already processing via
107+
// RunFlowAbility). For batch child jobs this is the real transition from
108+
// 'pending' → 'processing', ensuring recover-stuck only catches jobs
109+
// that genuinely started but never finished.
110+
$this->db_jobs->start_job( $job_id );
111+
105112
try {
106113
$engine_snapshot = datamachine_get_engine_data( $job_id );
107114
$engine = new EngineData( $engine_snapshot, $job_id );

inc/Abilities/Engine/PipelineBatchScheduler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ private function createChildJob(
314314
}
315315

316316
datamachine_set_engine_data( $child_job_id, $child_engine );
317-
$this->db_jobs->start_job( $child_job_id );
317+
318+
// Child job stays 'pending' until Action Scheduler actually picks it up.
319+
// ExecuteStepAbility transitions to 'processing' at execution time,
320+
// so recover-stuck only catches genuinely stuck jobs.
318321

319322
// Schedule the next step with this single DataPacket.
320323
// Uses the normal engine path — the child is a real pipeline job.

inc/Engine/Tasks/TaskScheduler.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ public static function schedule( string $taskType, array $params, array $context
9999
'scheduled_at' => current_time( 'mysql' ),
100100
) ) );
101101

102-
// Mark job as processing.
103-
$jobs_db->start_job( (int) $job_id, JobStatus::PROCESSING );
102+
// Job stays 'pending' until Action Scheduler fires handleTask().
103+
// The transition to 'processing' happens there, so recover-stuck
104+
// only catches jobs that genuinely started but never finished.
104105

105106
// Schedule Action Scheduler action.
106107
if ( function_exists( 'as_schedule_single_action' ) ) {
@@ -448,7 +449,11 @@ public static function processBatchChunk( string $batchId ): void {
448449
*/
449450
public static function handleTask( int $jobId ): void {
450451
$jobs_db = new Jobs();
451-
$job = $jobs_db->get_job( $jobId );
452+
453+
// Transition from 'pending' → 'processing' now that AS is running this.
454+
$jobs_db->start_job( $jobId, JobStatus::PROCESSING );
455+
456+
$job = $jobs_db->get_job( $jobId );
452457

453458
if ( ! $job ) {
454459
do_action(

0 commit comments

Comments
 (0)