1 | <?php |
||
46 | class QueuedJobDescriptor extends DataObject |
||
47 | { |
||
48 | /** |
||
49 | * {@inheritDoc} |
||
50 | * @var string |
||
51 | */ |
||
52 | private static $table_name = 'QueuedJobDescriptor'; |
||
|
|||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | private static $db = [ |
||
58 | 'JobTitle' => 'Varchar(255)', |
||
59 | 'Signature' => 'Varchar(64)', |
||
60 | 'Implementation' => 'Varchar(255)', |
||
61 | 'StartAfter' => 'DBDatetime', |
||
62 | 'JobStarted' => 'DBDatetime', |
||
63 | 'JobRestarted' => 'DBDatetime', |
||
64 | 'JobFinished' => 'DBDatetime', |
||
65 | 'TotalSteps' => 'Int', |
||
66 | 'StepsProcessed' => 'Int', |
||
67 | 'LastProcessedCount' => 'Int(-1)', // -1 means never checked, 0 means checked but no work is done |
||
68 | 'ResumeCounts' => 'Int', |
||
69 | 'SavedJobData' => 'Text', |
||
70 | 'SavedJobMessages' => 'Text', |
||
71 | 'JobStatus' => 'Varchar(16)', |
||
72 | 'JobType' => 'Varchar(16)', |
||
73 | ]; |
||
74 | |||
75 | /** |
||
76 | * @var array |
||
77 | */ |
||
78 | private static $has_one = [ |
||
79 | 'RunAs' => Member::class, |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * @var array |
||
84 | */ |
||
85 | private static $defaults = [ |
||
86 | 'JobStatus' => 'New', |
||
87 | 'ResumeCounts' => 0, |
||
88 | 'LastProcessedCount' => -1 // -1 means never checked, 0 means checked and none were processed |
||
89 | ]; |
||
90 | |||
91 | /** |
||
92 | * @var array |
||
93 | */ |
||
94 | private static $indexes = [ |
||
95 | 'JobStatus' => true, |
||
96 | 'StartAfter' => true, |
||
97 | 'Signature' => true, |
||
98 | ]; |
||
99 | |||
100 | /** |
||
101 | * @var array |
||
102 | */ |
||
103 | private static $casting = [ |
||
104 | 'Messages' => 'HTMLText', |
||
105 | ]; |
||
106 | |||
107 | /** |
||
108 | * @var array |
||
109 | */ |
||
110 | private static $searchable_fields = [ |
||
111 | 'JobTitle', |
||
112 | ]; |
||
113 | |||
114 | /** |
||
115 | * @var string |
||
116 | */ |
||
117 | private static $default_sort = 'Created DESC'; |
||
118 | |||
119 | public function requireDefaultRecords() |
||
124 | |||
125 | /** |
||
126 | * @return array |
||
127 | */ |
||
128 | public function summaryFields() |
||
144 | |||
145 | /** |
||
146 | * Pause this job, but only if it is waiting, running, or init |
||
147 | * |
||
148 | * @param bool $force Pause this job even if it's not waiting, running, or init |
||
149 | * |
||
150 | * @return bool Return true if this job was paused |
||
151 | */ |
||
152 | public function pause($force = false) |
||
166 | |||
167 | /** |
||
168 | * Resume this job and schedules it for execution |
||
169 | * |
||
170 | * @param bool $force Resume this job even if it's not paused or broken |
||
171 | * |
||
172 | * @return bool Return true if this job was resumed |
||
173 | */ |
||
174 | public function resume($force = false) |
||
185 | |||
186 | /** |
||
187 | * Restarts this job via a forced resume |
||
188 | */ |
||
189 | public function restart() |
||
193 | |||
194 | /** |
||
195 | * Called to indicate that the job is ready to be run on the queue. This is done either as the result of |
||
196 | * creating the job and adding it, or when resuming. |
||
197 | */ |
||
198 | public function activateOnQueue() |
||
208 | |||
209 | /** |
||
210 | * Gets the path to the queuedjob cache directory |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | protected function getJobDir() |
||
227 | |||
228 | public function execute() |
||
233 | |||
234 | /** |
||
235 | * Called when the job has completed and we want to cleanup anything the descriptor has lying around |
||
236 | * in caches or the like. |
||
237 | */ |
||
238 | public function cleanupJob() |
||
246 | |||
247 | public function onBeforeDelete() |
||
252 | |||
253 | /** |
||
254 | * Get all job messages as an HTML unordered list. |
||
255 | * |
||
256 | * @return string|null |
||
257 | */ |
||
258 | public function getMessages() |
||
271 | |||
272 | /** |
||
273 | * Get the last job message as a raw string |
||
274 | * |
||
275 | * @return string|null |
||
276 | */ |
||
277 | public function getLastMessage() |
||
286 | |||
287 | /** |
||
288 | * @return string |
||
289 | */ |
||
290 | public function getTitle() |
||
294 | |||
295 | /** |
||
296 | * Return a string representation of the numeric JobType |
||
297 | * @return string |
||
298 | */ |
||
299 | public function getJobTypeString() |
||
304 | |||
305 | |||
306 | /** |
||
307 | * Return a map of numeric JobType values to localisable string representations. |
||
308 | * @return array |
||
309 | */ |
||
310 | public function getJobTypeValues() |
||
318 | |||
319 | /** |
||
320 | * @return FieldList |
||
321 | */ |
||
322 | public function getCMSFields() |
||
358 | } |
||
359 |