PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.19
ووسلام – همگام سازی ووکامرس و باسلام v1.10.19
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 | JobManager.php +44 -12 1.10.81.10.19 View file →
@@ -23,21 +23,27 @@
23 23 public function createJob($jobType, $status = 'pending', $payload = null, $maxAttempts = 3)
24 24 {
25 25 global $wpdb;
26 26
27 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom plugin table; no object cache for these operational queries.
28 - return $wpdb->insert(
29 - $this->jobManagerTableName,
30 - array(
31 - 'job_type' => $jobType,
32 - 'status' => $status,
27 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom plugin table; no object cache for these operational queries.
28 + $result = $wpdb->insert(
29 + $this->jobManagerTableName,
30 + array(
31 + 'job_type' => $jobType,
32 + 'status' => $status,
33 33 'payload' => $payload,
34 34 'attempts' => 0,
35 35 'max_attempts' => $maxAttempts,
36 - 'created_at' => time(),
37 - )
38 - );
39 - }
36 + 'created_at' => time(),
37 + )
38 + );
39 +
40 + if ($result !== false) {
41 + do_action('sync_basalam_job_created', $jobType, $status, $payload);
42 + }
43 +
44 + return $result;
45 + }
40 46
41 47 public function getNextEligibleJob(string $jobType): ?object
42 48 {
43 49 global $wpdb;
@@ -58,10 +64,36 @@
58 64 public function hasAnyProcessingJob(): bool
59 65 {
60 66 return $this->getCountJobs(['status' => 'processing']) > 0;
61 67 }
62 -
63 - public function getJob($where = array())
68 +
69 + public function hasPendingOrStaleProcessingJobs(int $staleProcessingTimeoutSeconds = 120): bool
70 + {
71 + global $wpdb;
72 +
73 + $now = time();
74 + $staleBefore = $now - $staleProcessingTimeoutSeconds;
75 +
76 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Custom plugin table; identifier from $wpdb->prefix, not user input.
77 + $result = $wpdb->get_var($wpdb->prepare(
78 + "SELECT 1 FROM {$this->jobManagerTableName}
79 + WHERE (
80 + status = 'pending'
81 + AND (retry_after IS NULL OR retry_after <= %d)
82 + ) OR (
83 + status = 'processing'
84 + AND started_at IS NOT NULL
85 + AND started_at < %d
86 + )
87 + LIMIT 1",
88 + $now,
89 + $staleBefore
90 + ));
91 +
92 + return (string) $result === '1';
93 + }
94 +
95 + public function getJob($where = array())
64 96 {
65 97 global $wpdb;
66 98
67 99 if (empty($where)) return null;