1 | <?php |
||
44 | class QueuedJobDescriptor extends DataObject |
||
45 | { |
||
46 | /** |
||
47 | * {@inheritDoc} |
||
48 | * @var string |
||
49 | */ |
||
50 | private static $table_name = 'QueuedJobDescriptor'; |
||
|
|||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | */ |
||
55 | private static $db = [ |
||
56 | 'JobTitle' => 'Varchar(255)', |
||
57 | 'Signature' => 'Varchar(64)', |
||
58 | 'Implementation' => 'Varchar(255)', |
||
59 | 'StartAfter' => 'DBDatetime', |
||
60 | 'JobStarted' => 'DBDatetime', |
||
61 | 'JobRestarted' => 'DBDatetime', |
||
62 | 'JobFinished' => 'DBDatetime', |
||
63 | 'TotalSteps' => 'Int', |
||
64 | 'StepsProcessed' => 'Int', |
||
65 | 'LastProcessedCount' => 'Int(-1)', // -1 means never checked, 0 means checked but no work is done |
||
66 | 'ResumeCounts' => 'Int', |
||
67 | 'SavedJobData' => 'Text', |
||
68 | 'SavedJobMessages' => 'Text', |
||
69 | 'JobStatus' => 'Varchar(16)', |
||
70 | 'JobType' => 'Varchar(16)', |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * @var array |
||
75 | */ |
||
76 | private static $has_one = [ |
||
77 | 'RunAs' => 'SilverStripe\\Security\\Member', |
||
78 | ]; |
||
79 | |||
80 | /** |
||
81 | * @var array |
||
82 | */ |
||
83 | private static $defaults = [ |
||
84 | 'JobStatus' => 'New', |
||
85 | 'ResumeCounts' => 0, |
||
86 | 'LastProcessedCount' => -1 // -1 means never checked, 0 means checked and none were processed |
||
87 | ]; |
||
88 | |||
89 | /** |
||
90 | * @var array |
||
91 | */ |
||
92 | private static $indexes = [ |
||
93 | 'JobStatus' => true, |
||
94 | 'StartAfter' => true, |
||
95 | 'Signature' => true, |
||
96 | ]; |
||
97 | |||
98 | /** |
||
99 | * @var array |
||
100 | */ |
||
101 | private static $casting = [ |
||
102 | 'Messages' => 'HTMLText', |
||
103 | ]; |
||
104 | |||
105 | /** |
||
106 | * @var array |
||
107 | */ |
||
108 | private static $searchable_fields = [ |
||
109 | 'JobTitle', |
||
110 | ]; |
||
111 | |||
112 | /** |
||
113 | * @var string |
||
114 | */ |
||
115 | private static $default_sort = 'Created DESC'; |
||
116 | |||
117 | public function requireDefaultRecords() |
||
122 | |||
123 | /** |
||
124 | * @return array |
||
125 | */ |
||
126 | public function summaryFields() |
||
142 | |||
143 | /** |
||
144 | * Pause this job, but only if it is waiting, running, or init |
||
145 | * |
||
146 | * @param bool $force Pause this job even if it's not waiting, running, or init |
||
147 | * |
||
148 | * @return bool Return true if this job was paused |
||
149 | */ |
||
150 | public function pause($force = false) |
||
162 | |||
163 | /** |
||
164 | * Resume this job and schedules it for execution |
||
165 | * |
||
166 | * @param bool $force Resume this job even if it's not paused or broken |
||
167 | * |
||
168 | * @return bool Return true if this job was resumed |
||
169 | */ |
||
170 | public function resume($force = false) |
||
181 | |||
182 | /** |
||
183 | * Restarts this job via a forced resume |
||
184 | */ |
||
185 | public function restart() |
||
189 | |||
190 | /** |
||
191 | * Called to indicate that the job is ready to be run on the queue. This is done either as the result of |
||
192 | * creating the job and adding it, or when resuming. |
||
193 | */ |
||
194 | public function activateOnQueue() |
||
203 | |||
204 | /** |
||
205 | * Gets the path to the queuedjob cache directory |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | protected function getJobDir() |
||
222 | |||
223 | public function execute() |
||
228 | |||
229 | /** |
||
230 | * Called when the job has completed and we want to cleanup anything the descriptor has lying around |
||
231 | * in caches or the like. |
||
232 | */ |
||
233 | public function cleanupJob() |
||
241 | |||
242 | public function onBeforeDelete() |
||
247 | |||
248 | /** |
||
249 | * Get all job messages as an HTML unordered list. |
||
250 | * |
||
251 | * @return string|void |
||
252 | */ |
||
253 | public function getMessages() |
||
263 | |||
264 | /** |
||
265 | * Get the last job message as a raw string |
||
266 | * |
||
267 | * @return string|void |
||
268 | */ |
||
269 | public function getLastMessage() |
||
279 | |||
280 | /** |
||
281 | * @return string |
||
282 | */ |
||
283 | public function getTitle() |
||
287 | |||
288 | /** |
||
289 | * Return a string representation of the numeric JobType |
||
290 | * @return string |
||
291 | */ |
||
292 | public function getJobTypeString() |
||
297 | |||
298 | |||
299 | /** |
||
300 | * Return a map of numeric JobType values to localisable string representations. |
||
301 | * @return array |
||
302 | */ |
||
303 | public function getJobTypeValues() |
||
311 | |||
312 | /** |
||
313 | * @return FieldList |
||
314 | */ |
||
315 | public function getCMSFields() |
||
351 | } |
||
352 |