fix: process_batch() never received its args, so every batch silently no-op'd

as_enqueue_async_action() spreads the args array into separate positional
parameters on the hooked callback, it does not pass one combined array.
process_batch() was registered with accepted_args=1 and tried to read
$args['run_id']/$args['product_ids'] off what was actually just the run_id
string - the run_id comparison then always failed and every batch returned
immediately without doing any work, while Action Scheduler still marked
each action complete (no exception was thrown). Found by tracing why 896
queued batches all reported "complete" within seconds with zero products
actually synced.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-09 14:00:31 +02:00
parent 5ac5c626f3
commit 8e093f4c76

View File

@@ -51,7 +51,7 @@ class WBC_Batch_Sync {
* Register the Action Scheduler batch handler
*/
public function register_hooks() {
add_action( self::ACTION_HOOK, array( $this, 'process_batch' ), 10, 1 );
add_action( self::ACTION_HOOK, array( $this, 'process_batch' ), 10, 2 );
}
/**
@@ -169,12 +169,15 @@ class WBC_Batch_Sync {
/**
* Process a single batch (called by Action Scheduler)
*
* @param array $args Action args: run_id, product_ids.
* Action Scheduler spreads the associative args array passed to
* as_enqueue_async_action() into separate positional parameters here
* (it does not pass a single combined array) - the parameter order
* must match the key order used when the action was enqueued.
*
* @param string $run_id Run ID this batch belongs to.
* @param array $product_ids WooCommerce product IDs in this batch.
*/
public function process_batch( $args ) {
$run_id = $args['run_id'] ?? '';
$product_ids = $args['product_ids'] ?? array();
public function process_batch( $run_id, $product_ids = array() ) {
$run = get_option( self::RUN_OPTION, array() );
// A newer sync superseded this run (e.g. re-triggered manually) - drop it.