fix: run product sync in background batches to avoid 502 on large catalogs
Manual and scheduled sync previously processed every WooCommerce product inline in a single PHP request/AJAX call, with several sequential BC API calls per product. At real catalog sizes this exceeds PHP's max_execution_time and the proxy's read timeout, surfacing as a 502 Bad Gateway on "Sync Now". Adds WBC_Batch_Sync, which queues the catalog in chunks of 25 via Action Scheduler (bundled with WooCommerce) and processes them asynchronously. The manual sync AJAX call now returns immediately after queuing, and the admin UI polls for progress instead of waiting on one long request. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,6 +96,10 @@ class WBC_Loader {
|
||||
$cron = new WBC_Cron();
|
||||
$this->add_action( 'wbc_product_sync_event', $cron, 'run_scheduled_sync' );
|
||||
|
||||
// Register background batch sync handler (Action Scheduler)
|
||||
$batch_sync = new WBC_Batch_Sync();
|
||||
$batch_sync->register_hooks();
|
||||
|
||||
// Register order sync handler
|
||||
$order_sync = new WBC_Order_Sync();
|
||||
$this->add_action( 'woocommerce_order_status_processing', $order_sync, 'sync_order', 10, 1 );
|
||||
@@ -109,6 +113,7 @@ class WBC_Loader {
|
||||
$this->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_scripts' );
|
||||
$this->add_action( 'wp_ajax_wbc_test_connection', $admin, 'ajax_test_connection' );
|
||||
$this->add_action( 'wp_ajax_wbc_manual_sync', $admin, 'ajax_manual_sync' );
|
||||
$this->add_action( 'wp_ajax_wbc_sync_status', $admin, 'ajax_sync_status' );
|
||||
$this->add_action( 'wp_ajax_wbc_clear_logs', $admin, 'ajax_clear_logs' );
|
||||
$this->add_action( 'wp_ajax_wbc_get_companies', $admin, 'ajax_get_companies' );
|
||||
$this->add_action( 'admin_init', $admin, 'handle_csv_export' );
|
||||
|
||||
Reference in New Issue
Block a user