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() |
||
141 | |||
142 | /** |
||
143 | * Pause this job, but only if it is waiting, running, or init |
||
144 | * |
||
145 | * @param bool $force Pause this job even if it's not waiting, running, or init |
||
146 | * |
||
147 | * @return bool Return true if this job was paused |
||
148 | */ |
||
149 | public function pause($force = false) |
||
161 | |||
162 | /** |
||
163 | * Resume this job and schedules it for execution |
||
164 | * |
||
165 | * @param bool $force Resume this job even if it's not paused or broken |
||
166 | * |
||
167 | * @return bool Return true if this job was resumed |
||
168 | */ |
||
169 | public function resume($force = false) |
||
180 | |||
181 | /** |
||
182 | * Restarts this job via a forced resume |
||
183 | */ |
||
184 | public function restart() |
||
188 | |||
189 | /** |
||
190 | * Called to indicate that the job is ready to be run on the queue. This is done either as the result of |
||
191 | * creating the job and adding it, or when resuming. |
||
192 | */ |
||
193 | public function activateOnQueue() |
||
202 | |||
203 | /** |
||
204 | * Gets the path to the queuedjob cache directory |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | protected function getJobDir() |
||
221 | |||
222 | public function execute() |
||
227 | |||
228 | /** |
||
229 | * Called when the job has completed and we want to cleanup anything the descriptor has lying around |
||
230 | * in caches or the like. |
||
231 | */ |
||
232 | public function cleanupJob() |
||
240 | |||
241 | public function onBeforeDelete() |
||
246 | |||
247 | /** |
||
248 | * Get all job messages as an HTML unordered list. |
||
249 | * |
||
250 | * @return string|void |
||
251 | */ |
||
252 | public function getMessages() |
||
262 | |||
263 | /** |
||
264 | * Get the last job message as a raw string |
||
265 | * |
||
266 | * @return string|void |
||
267 | */ |
||
268 | public function getLastMessage() |
||
278 | |||
279 | /** |
||
280 | * @return string |
||
281 | */ |
||
282 | public function getTitle() |
||
286 | |||
287 | /** |
||
288 | * @return FieldList |
||
289 | */ |
||
290 | public function getCMSFields() |
||
330 | } |
||
331 |