PluginProbe ʕ •ᴥ•ʔ
Download Manager / 3.3.63
Download Manager v3.3.63
3.3.63 3.3.62 3.3.61 3.3.60 3.3.59 3.3.58 3.3.57 3.3.56 trunk 2.1.3 2.3.0 2.5.96 2.5.97 2.6.2 2.6.96 2.8.3 2.9.99 3.0.4 3.1.05 3.1.07 3.1.08 3.1.11 3.1.12 3.1.14 3.1.17 3.1.18 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.2.04 3.2.13 3.2.14 3.2.16 3.2.18 3.2.19 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 3.2.27 3.2.28 3.2.29 3.2.30 3.2.31 3.2.32 3.2.33 3.2.34 3.2.35 3.2.37 3.2.38 3.2.39 3.2.40 3.2.41 3.2.42 3.2.43 3.2.44 3.2.45 3.2.46 3.2.47 3.2.48 3.2.49 3.2.50 3.2.51 3.2.52 3.2.53 3.2.54 3.2.55 3.2.56 3.2.57 3.2.58 3.2.59 3.2.60 3.2.61 3.2.63 3.2.64 3.2.65 3.2.66 3.2.67 3.2.68 3.2.69 3.2.70 3.2.71 3.2.72 3.2.73 3.2.74 3.2.75 3.2.76 3.2.77 3.2.78 3.2.79 3.2.80 3.2.81 3.2.82 3.2.83 3.2.84 3.2.85 3.2.86 3.2.87 3.2.88 3.2.89 3.2.90 3.2.91 3.2.92 3.2.93 3.2.94 3.2.95 3.2.96 3.2.97 3.2.98 3.2.99 3.3.00 3.3.01 3.3.02 3.3.03 3.3.04 3.3.05 3.3.06 3.3.07 3.3.08 3.3.09 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 3.3.16 3.3.17 3.3.18 3.3.19 3.3.20 3.3.21 3.3.22 3.3.23 3.3.24 3.3.25 3.3.26 3.3.27 3.3.28 3.3.29 3.3.30 3.3.31 3.3.32 3.3.33 3.3.34 3.3.35 3.3.36 3.3.37 3.3.38 3.3.39 3.3.40 3.3.41 3.3.42 3.3.43 3.3.44 3.3.45 3.3.46 3.3.47 3.3.48 3.3.49 3.3.50 3.3.51 3.3.52 3.3.53 3.3.54 3.3.55
download-manager / src / __ / Jobs / JobBuilder.php
download-manager / src / __ / Jobs Last commit date
ActivityReportJob.php 2 days ago CleanupJob.php 2 days ago DeleteExpiredJob.php 2 days ago Job.php 2 days ago JobBuilder.php 2 days ago JobHandler.php 2 days ago SendEmailJob.php 2 days ago
JobBuilder.php
272 lines
1 <?php
2 /**
3 * Job Builder
4 *
5 * Fluent interface for creating and scheduling jobs.
6 *
7 * @package WPDM\__\Jobs
8 * @since 7.0.1
9 */
10
11 namespace WPDM\__\Jobs;
12
13 use WPDM\__\CronJob;
14
15 class JobBuilder
16 {
17 /**
18 * Job handler class name
19 *
20 * @var string
21 */
22 private $handler;
23
24 /**
25 * Job payload data
26 *
27 * @var array
28 */
29 private $data = [];
30
31 /**
32 * Queue name
33 *
34 * @var string
35 */
36 private $queue = 'default';
37
38 /**
39 * Job priority (1-10, higher = sooner)
40 *
41 * @var int
42 */
43 private $priority = 5;
44
45 /**
46 * Delay in seconds before execution
47 *
48 * @var int
49 */
50 private $delay = 0;
51
52 /**
53 * Maximum retry attempts
54 *
55 * @var int
56 */
57 private $maxAttempts = 3;
58
59 /**
60 * Number of times to repeat (0 = infinite for scheduled jobs)
61 *
62 * @var int
63 */
64 private $repeat = 1;
65
66 /**
67 * Interval between repeats in seconds
68 *
69 * @var int
70 */
71 private $interval = 0;
72
73 /**
74 * Unique job code (to prevent duplicates)
75 *
76 * @var string|null
77 */
78 private $uniqueCode = null;
79
80 /**
81 * Constructor
82 *
83 * @param string $handler Job handler class name
84 */
85 public function __construct(string $handler)
86 {
87 $this->handler = $handler;
88 }
89
90 /**
91 * Set job payload data
92 *
93 * @param array $data
94 * @return self
95 */
96 public function withData(array $data): self
97 {
98 $this->data = $data;
99 return $this;
100 }
101
102 /**
103 * Set queue name
104 *
105 * @param string $queue
106 * @return self
107 */
108 public function onQueue(string $queue): self
109 {
110 $this->queue = $queue;
111 return $this;
112 }
113
114 /**
115 * Set job priority (1-10)
116 *
117 * @param int $priority
118 * @return self
119 */
120 public function priority(int $priority): self
121 {
122 $this->priority = max(1, min(10, $priority));
123 return $this;
124 }
125
126 /**
127 * Delay execution by seconds
128 *
129 * @param int $seconds
130 * @return self
131 */
132 public function delay(int $seconds): self
133 {
134 $this->delay = max(0, $seconds);
135 return $this;
136 }
137
138 /**
139 * Delay execution until a specific timestamp
140 *
141 * @param int $timestamp
142 * @return self
143 */
144 public function delayUntil(int $timestamp): self
145 {
146 $this->delay = max(0, $timestamp - time());
147 return $this;
148 }
149
150 /**
151 * Set maximum retry attempts
152 *
153 * @param int $attempts
154 * @return self
155 */
156 public function attempts(int $attempts): self
157 {
158 $this->maxAttempts = max(1, $attempts);
159 return $this;
160 }
161
162 /**
163 * Set unique code to prevent duplicate jobs
164 *
165 * @param string $code
166 * @return self
167 */
168 public function unique(string $code): self
169 {
170 $this->uniqueCode = $code;
171 return $this;
172 }
173
174 /**
175 * Run every N minutes
176 *
177 * @param int $minutes
178 * @return self
179 */
180 public function everyMinutes(int $minutes): self
181 {
182 $this->repeat = 0; // Infinite
183 $this->interval = $minutes * 60;
184 return $this;
185 }
186
187 /**
188 * Run hourly
189 *
190 * @return self
191 */
192 public function hourly(): self
193 {
194 return $this->everyMinutes(60);
195 }
196
197 /**
198 * Run every N hours
199 *
200 * @param int $hours
201 * @return self
202 */
203 public function everyHours(int $hours): self
204 {
205 return $this->everyMinutes($hours * 60);
206 }
207
208 /**
209 * Run daily
210 *
211 * @return self
212 */
213 public function daily(): self
214 {
215 return $this->everyMinutes(1440);
216 }
217
218 /**
219 * Run weekly
220 *
221 * @return self
222 */
223 public function weekly(): self
224 {
225 return $this->everyMinutes(10080);
226 }
227
228 /**
229 * Repeat N times with interval
230 *
231 * @param int $times Number of times to repeat
232 * @param int $intervalSeconds Seconds between each execution
233 * @return self
234 */
235 public function repeat(int $times, int $intervalSeconds = 0): self
236 {
237 $this->repeat = max(1, $times);
238 $this->interval = max(0, $intervalSeconds);
239 return $this;
240 }
241
242 /**
243 * Create the job and add to queue
244 *
245 * @return int|false Job ID on success, false on failure
246 */
247 public function create()
248 {
249 return CronJob::create(
250 $this->handler,
251 $this->data,
252 time() + $this->delay,
253 $this->repeat,
254 $this->interval,
255 $this->queue,
256 $this->priority,
257 $this->maxAttempts,
258 $this->uniqueCode
259 );
260 }
261
262 /**
263 * Alias for create()
264 *
265 * @return int|false
266 */
267 public function dispatch()
268 {
269 return $this->create();
270 }
271 }
272