PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.20
ووسلام – همگام سازی ووکامرس و باسلام v1.10.20
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
← All changes | JobsRunner.php +10 -10 1.10.151.10.20 View file →
@@ -31,11 +31,11 @@
31 31 $CheckHttpBlockService
32 32 ) {
33 33 add_action('wp_ajax_' . self::ASYNC_ACTION, [$this, 'handleAsyncRequest']);
34 34 add_action('wp_ajax_nopriv_' . self::ASYNC_ACTION, [$this, 'handleAsyncRequest']);
35 - // Keep database work out of shutdown, where another callback may have
36 - // left the shared mysqli connection with an unread result set.
37 - add_action('init', [$this, 'maybeDispatchAsyncRequest'], 10, 0);
35 + // Probe and dispatch after the response path so normal storefront
36 + // requests never pay for the queue query or loopback HTTP request.
37 + add_action('shutdown', [$this, 'maybeDispatchAsyncRequest'], PHP_INT_MAX);
38 38 add_action('sync_basalam_job_created', [$this, 'maybeDispatchAsyncRequest'], 10, 0);
39 39
40 40 $this->jobManager = $jobManager;
41 41 $this->jobExecutor = $jobExecutor;
@@ -44,24 +44,24 @@
44 44 }
45 45
46 46 public function maybeDispatchAsyncRequest(): void
47 47 {
48 - // Retain a guard for third-party callers that may still invoke this
49 - // method during shutdown even though no shutdown hook is registered.
50 - if (function_exists('did_action') && did_action('shutdown')) return;
51 48 if ($this->isCurrentAsyncRequest()) return;
52 49 if ($this->CheckHttpBlockService->SyncBasalamHttpBlock()) return;
53 50 if (get_transient(self::ASYNC_DISPATCH_LOCK_TRANSIENT)) return;
54 51
55 - if (!$this->jobManager->hasPendingOrStaleProcessingJobs(self::STALE_PROCESSING_TIMEOUT_SECONDS)) {
56 - return;
57 - }
58 -
52 + // Reserve the dispatch lease before probing the queue. This keeps
53 + // concurrent shutdown callbacks from all running the queue query and
54 + // dispatching duplicate async workers.
59 55 set_transient(
60 56 self::ASYNC_DISPATCH_LOCK_TRANSIENT,
61 57 1,
62 58 self::ASYNC_DISPATCH_LOCK_SECONDS
63 59 );
60 +
61 + if (!$this->jobManager->hasPendingOrStaleProcessingJobs(self::STALE_PROCESSING_TIMEOUT_SECONDS)) {
62 + return;
63 + }
64 64
65 65 $this->dispatchAsyncRequest();
66 66 }
67 67