Repository navigation
Expand file tree
/
Copy pathCrontab.php
More file actions
279 lines (224 loc) · 6.53 KB
/
Copy pathCrontab.php
File metadata and controls
279 lines (224 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Crontab;
use Carbon\Carbon;
use DateTimeZone;
use Hyperf\Conditionable\Conditionable;
use Hyperf\Engine\Channel;
class Crontab
{
use Conditionable;
use ManagesFrequencies;
protected ?string $name = null;
protected string $type = 'callback';
protected ?string $rule = null;
protected bool $singleton = false;
protected string $mutexPool = 'default';
protected int $mutexExpires = 60;
protected bool $onOneServer = false;
protected mixed $callback = null;
protected ?string $memo = null;
protected ?Carbon $executeTime = null;
protected bool $enable = true;
protected null|DateTimeZone|string $timezone = null;
protected ?Channel $running = null;
protected array $environments = [];
protected array $options = [];
public function __clone()
{
$this->running = new Channel(1);
}
public function __serialize(): array
{
return [
"\x00*\x00name" => $this->name,
"\x00*\x00type" => $this->type,
"\x00*\x00rule" => $this->rule,
"\x00*\x00singleton" => $this->singleton,
"\x00*\x00mutexPool" => $this->mutexPool,
"\x00*\x00mutexExpires" => $this->mutexExpires,
"\x00*\x00onOneServer" => $this->onOneServer,
"\x00*\x00callback" => $this->callback,
"\x00*\x00memo" => $this->memo,
"\x00*\x00executeTime" => $this->executeTime,
"\x00*\x00enable" => $this->enable,
"\x00*\x00timezone" => $this->timezone,
"\x00*\x00environments" => $this->environments,
"\x00*\x00options" => $this->options,
];
}
public function __unserialize(array $data): void
{
$this->name = $data["\x00*\x00name"] ?? $this->name;
$this->type = $data["\x00*\x00type"] ?? $this->type;
$this->rule = $data["\x00*\x00rule"] ?? $this->rule;
$this->singleton = $data["\x00*\x00singleton"] ?? $this->singleton;
$this->mutexPool = $data["\x00*\x00mutexPool"] ?? $this->mutexPool;
$this->mutexExpires = $data["\x00*\x00mutexExpires"] ?? $this->mutexExpires;
$this->onOneServer = $data["\x00*\x00onOneServer"] ?? $this->onOneServer;
$this->callback = $data["\x00*\x00callback"] ?? $this->callback;
$this->memo = $data["\x00*\x00memo"] ?? $this->memo;
$this->executeTime = $data["\x00*\x00executeTime"] ?? $this->executeTime;
$this->enable = $data["\x00*\x00enable"] ?? $this->enable;
$this->running = new Channel(1);
$this->timezone = $data["\x00*\x00timezone"] ?? $this->timezone;
$this->environments = $data["\x00*\x00environments"] ?? $this->environments;
$this->options = $data["\x00*\x00options"] ?? $this->options;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getRule(): ?string
{
return $this->rule;
}
public function setRule(?string $rule): static
{
$this->rule = $rule;
return $this;
}
public function isSingleton(): bool
{
return $this->singleton;
}
public function setSingleton(bool $singleton): static
{
$this->singleton = $singleton;
return $this;
}
public function getMutexPool(): string
{
return $this->mutexPool;
}
public function setMutexPool(string $mutexPool): static
{
$this->mutexPool = $mutexPool;
return $this;
}
public function getMutexExpires(): int
{
return $this->mutexExpires;
}
public function setMutexExpires(int $mutexExpires): static
{
$this->mutexExpires = $mutexExpires;
return $this;
}
public function isOnOneServer(): bool
{
return $this->onOneServer;
}
public function setOnOneServer(bool $onOneServer): static
{
$this->onOneServer = $onOneServer;
return $this;
}
public function getCallback(): mixed
{
return $this->callback;
}
public function setCallback(mixed $callback): static
{
$this->callback = $callback;
return $this;
}
public function getMemo(): ?string
{
return $this->memo;
}
public function setMemo(?string $memo): static
{
$this->memo = $memo;
return $this;
}
public function getType(): string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
public function getExecuteTime(): ?Carbon
{
return $this->executeTime;
}
public function setExecuteTime(Carbon $executeTime): static
{
$this->executeTime = $executeTime;
return $this;
}
public function isEnable(): bool
{
return $this->enable;
}
public function setEnable(bool $enable): static
{
$this->enable = $enable;
return $this;
}
public function getTimezone(): null|DateTimeZone|string
{
return $this->timezone;
}
public function setTimezone(DateTimeZone|string $timezone): static
{
$this->timezone = $timezone;
return $this;
}
/**
* Limit the environments the command should run in.
*
* @param array|mixed $environments
* @return $this
*/
public function setEnvironments($environments): static
{
$this->environments = is_array($environments) ? $environments : func_get_args();
return $this;
}
public function getEnvironments(): array
{
return $this->environments;
}
public function setOptions(array $options): static
{
$this->options = $options;
return $this;
}
public function getOptions(): array
{
return $this->options;
}
public function runsInEnvironment(string $environment): bool
{
return empty($this->environments) || in_array($environment, $this->environments, true);
}
public function complete(): void
{
$this->running?->close();
}
public function close(): void
{
$this->running?->close();
}
public function wait(): void
{
$this->running?->pop();
}
}