1 | <?php |
||
39 | class TaskRunnerController extends AbstractController |
||
40 | { |
||
41 | /** |
||
42 | * Retrieve the task list. |
||
43 | * |
||
44 | * @return JsonResponse |
||
45 | * |
||
46 | * @ApiDoc( |
||
47 | * section="tasks", |
||
48 | * statusCodes = { |
||
49 | * 200 = "When everything worked out ok" |
||
50 | * }, |
||
51 | * authentication = true, |
||
52 | * authenticationRoles = { |
||
53 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
54 | * }, |
||
55 | * ) |
||
56 | * @ApiDescription( |
||
57 | * response={ |
||
58 | * "status" = { |
||
59 | * "dataType" = "string", |
||
60 | * "description" = "OK on success" |
||
61 | * }, |
||
62 | * "tasks" = { |
||
63 | * "id" = { |
||
64 | * "dataType" = "string", |
||
65 | * "description" = "The task id." |
||
66 | * }, |
||
67 | * "status" = { |
||
68 | * "dataType" = "string", |
||
69 | * "description" = "The task status." |
||
70 | * }, |
||
71 | * "type" = { |
||
72 | * "dataType" = "string", |
||
73 | * "description" = "The type of the task." |
||
74 | * }, |
||
75 | * "created_at" = { |
||
76 | * "dataType" = "string", |
||
77 | * "description" = "The date the task was created in ISO 8601 format." |
||
78 | * }, |
||
79 | * "user_data" = { |
||
80 | * "dataType" = "object", |
||
81 | * "description" = "The user submitted additional data." |
||
82 | * } |
||
83 | * } |
||
84 | * } |
||
85 | * ) |
||
86 | */ |
||
87 | public function getTasksAction() |
||
97 | |||
98 | /** |
||
99 | * Retrieve the given task task. |
||
100 | * |
||
101 | * @param string $taskId The id of the task to retrieve. |
||
102 | * |
||
103 | * @param Request $request The request. |
||
104 | * |
||
105 | * @return JsonResponse |
||
106 | * |
||
107 | * @throws NotFoundHttpException When the task could not be found. |
||
108 | * |
||
109 | * @ApiDoc( |
||
110 | * section="tasks", |
||
111 | * statusCodes = { |
||
112 | * 200 = "When everything worked out ok" |
||
113 | * }, |
||
114 | * authentication = true, |
||
115 | * authenticationRoles = { |
||
116 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
117 | * }, |
||
118 | * filters = { |
||
119 | * { |
||
120 | * "name"="offset", |
||
121 | * "dataType" = "int", |
||
122 | * "description"="If present, the output will be returned from the given byte offset." |
||
123 | * } |
||
124 | * } |
||
125 | * ) |
||
126 | * @ApiDescription( |
||
127 | * response={ |
||
128 | * "status" = { |
||
129 | * "dataType" = "string", |
||
130 | * "description" = "OK on success" |
||
131 | * }, |
||
132 | * "task" = { |
||
133 | * "id" = { |
||
134 | * "dataType" = "string", |
||
135 | * "description" = "The task id." |
||
136 | * }, |
||
137 | * "status" = { |
||
138 | * "dataType" = "string", |
||
139 | * "description" = "The task status." |
||
140 | * }, |
||
141 | * "type" = { |
||
142 | * "dataType" = "string", |
||
143 | * "description" = "The type of the task." |
||
144 | * }, |
||
145 | * "created_at" = { |
||
146 | * "dataType" = "string", |
||
147 | * "description" = "The date the task was created in ISO 8601 format." |
||
148 | * }, |
||
149 | * "user_data" = { |
||
150 | * "dataType" = "object", |
||
151 | * "description" = "The user submitted additional data." |
||
152 | * }, |
||
153 | * "output" = { |
||
154 | * "dataType" = "string", |
||
155 | * "description" = "The command line output of the task." |
||
156 | * } |
||
157 | * } |
||
158 | * } |
||
159 | * ) |
||
160 | */ |
||
161 | public function getTaskAction($taskId, Request $request) |
||
177 | |||
178 | /** |
||
179 | * Queue a task in the list. |
||
180 | * |
||
181 | * @param Request $request The request. |
||
182 | * |
||
183 | * @return JsonResponse |
||
184 | * |
||
185 | * @throws NotAcceptableHttpException When the payload is invalid. |
||
186 | * |
||
187 | * @ApiDoc( |
||
188 | * section="tasks", |
||
189 | * statusCodes = { |
||
190 | * 201 = "When everything worked out ok", |
||
191 | * 406 = "When the payload is invalid" |
||
192 | * }, |
||
193 | * authentication = true, |
||
194 | * authenticationRoles = { |
||
195 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
196 | * }, |
||
197 | * ) |
||
198 | * @ApiDescription( |
||
199 | * response={ |
||
200 | * "status" = { |
||
201 | * "dataType" = "string", |
||
202 | * "description" = "OK on success" |
||
203 | * }, |
||
204 | * "task" = { |
||
205 | * "id" = { |
||
206 | * "dataType" = "string", |
||
207 | * "description" = "The task id." |
||
208 | * }, |
||
209 | * "status" = { |
||
210 | * "dataType" = "string", |
||
211 | * "description" = "The task status." |
||
212 | * }, |
||
213 | * "type" = { |
||
214 | * "dataType" = "string", |
||
215 | * "description" = "The type of the task." |
||
216 | * }, |
||
217 | * "user_data" = { |
||
218 | * "dataType" = "object", |
||
219 | * "description" = "The user submitted additional data." |
||
220 | * }, |
||
221 | * "created_at" = { |
||
222 | * "dataType" = "string", |
||
223 | * "description" = "The date the task was created in ISO 8601 format." |
||
224 | * } |
||
225 | * } |
||
226 | * } |
||
227 | * ) |
||
228 | */ |
||
229 | public function addTaskAction(Request $request) |
||
254 | |||
255 | /** |
||
256 | * Remove a task from the list. |
||
257 | * |
||
258 | * @param string $taskId The id of the task to remove. |
||
259 | * |
||
260 | * @return JsonResponse |
||
261 | * |
||
262 | * @throws NotFoundHttpException When the given task could not be found. |
||
263 | * @throws NotAcceptableHttpException When trying to delete a running task. |
||
264 | * |
||
265 | * @ApiDoc( |
||
266 | * section="tasks", |
||
267 | * statusCodes = { |
||
268 | * 200 = "When everything worked out ok" |
||
269 | * }, |
||
270 | * authentication = true, |
||
271 | * authenticationRoles = { |
||
272 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
273 | * }, |
||
274 | * ) |
||
275 | * @ApiDescription( |
||
276 | * response={ |
||
277 | * "status" = { |
||
278 | * "dataType" = "string", |
||
279 | * "description" = "OK on success" |
||
280 | * } |
||
281 | * } |
||
282 | * ) |
||
283 | */ |
||
284 | public function deleteTaskAction($taskId) |
||
306 | |||
307 | /** |
||
308 | * Starts the next pending task if any. |
||
309 | * |
||
310 | * @return JsonResponse |
||
311 | * |
||
312 | * @throws NotFoundHttpException When no task could be found. |
||
313 | * @throws NotAcceptableHttpException When a task is already running and holds the lock. |
||
314 | * |
||
315 | * @ApiDoc( |
||
316 | * section="tasks", |
||
317 | * statusCodes = { |
||
318 | * 200 = "When everything worked out ok", |
||
319 | * 404 = "When no pending task has been found", |
||
320 | * 406 = "When another task is still running" |
||
321 | * }, |
||
322 | * authentication = true, |
||
323 | * authenticationRoles = { |
||
324 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
325 | * }, |
||
326 | * ) |
||
327 | * @ApiDescription( |
||
328 | * response={ |
||
329 | * "status" = { |
||
330 | * "dataType" = "string", |
||
331 | * "description" = "OK on success" |
||
332 | * }, |
||
333 | * "task" = { |
||
334 | * "id" = { |
||
335 | * "dataType" = "string", |
||
336 | * "description" = "The task id." |
||
337 | * }, |
||
338 | * "status" = { |
||
339 | * "dataType" = "string", |
||
340 | * "description" = "The task status." |
||
341 | * }, |
||
342 | * "type" = { |
||
343 | * "dataType" = "string", |
||
344 | * "description" = "The type of the task." |
||
345 | * }, |
||
346 | * "created_at" = { |
||
347 | * "dataType" = "string", |
||
348 | * "description" = "The date the task was created in ISO 8601 format." |
||
349 | * }, |
||
350 | * "user_data" = { |
||
351 | * "dataType" = "object", |
||
352 | * "description" = "The user submitted additional data." |
||
353 | * } |
||
354 | * } |
||
355 | * } |
||
356 | * ) |
||
357 | */ |
||
358 | public function runAction() |
||
388 | |||
389 | /** |
||
390 | * Spawn a detached process for a task. |
||
391 | * |
||
392 | * @param Task $task The task to spawn a process for. |
||
393 | * |
||
394 | * @return void |
||
395 | * |
||
396 | * @throws \RuntimeException When the task could not be started. |
||
397 | */ |
||
398 | private function spawn(Task $task) |
||
437 | |||
438 | /** |
||
439 | * Convert a task to an array. |
||
440 | * |
||
441 | * @param Task $task The task to convert. |
||
442 | * |
||
443 | * @param bool $addOutput Flag determining if the output shall get added or not. |
||
444 | * |
||
445 | * @param null $outputOffset The output offset to use. |
||
446 | * |
||
447 | * @return array |
||
448 | */ |
||
449 | private function convertTaskToArray(Task $task, $addOutput = false, $outputOffset = null) |
||
465 | |||
466 | /** |
||
467 | * Create a JsonResponse based on an array of tasks. |
||
468 | * |
||
469 | * @param array[] $tasks The task data. |
||
470 | * |
||
471 | * @param bool $isCollection Flag if the data is a task collection. |
||
472 | * |
||
473 | * @param string $status Status code string. |
||
474 | * |
||
475 | * @param int $httpStatus HTTP Status to send. |
||
476 | * |
||
477 | * @return JsonResponse |
||
478 | */ |
||
479 | private function createJsonResponse( |
||
492 | } |
||
493 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: