1 | <?php |
||
38 | class TaskRunnerController extends AbstractController |
||
39 | { |
||
40 | /** |
||
41 | * Retrieve the task list. |
||
42 | * |
||
43 | * @return JsonResponse |
||
44 | * |
||
45 | * @ApiDoc( |
||
46 | * section="tasks", |
||
47 | * statusCodes = { |
||
48 | * 200 = "When everything worked out ok" |
||
49 | * }, |
||
50 | * authentication = true, |
||
51 | * authenticationRoles = { |
||
52 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
53 | * }, |
||
54 | * ) |
||
55 | * @ApiDescription( |
||
56 | * response={ |
||
57 | * "status" = { |
||
58 | * "dataType" = "string", |
||
59 | * "description" = "OK on success" |
||
60 | * }, |
||
61 | * "tasks" = { |
||
62 | * "id" = { |
||
63 | * "dataType" = "string", |
||
64 | * "description" = "The task id." |
||
65 | * }, |
||
66 | * "status" = { |
||
67 | * "dataType" = "string", |
||
68 | * "description" = "The task status." |
||
69 | * }, |
||
70 | * "type" = { |
||
71 | * "dataType" = "string", |
||
72 | * "description" = "The type of the task." |
||
73 | * }, |
||
74 | * "created_at" = { |
||
75 | * "dataType" = "string", |
||
76 | * "description" = "The date the task was created in ISO 8601 format." |
||
77 | * }, |
||
78 | * "output" = { |
||
79 | * "dataType" = "string", |
||
80 | * "description" = "The command line output of the task." |
||
81 | * } |
||
82 | * } |
||
83 | * ) |
||
84 | */ |
||
85 | public function getTasksAction() |
||
95 | |||
96 | /** |
||
97 | * Retrieve the given task task. |
||
98 | * |
||
99 | * @param string $taskId The id of the task to retrieve. |
||
100 | * |
||
101 | * @param Request $request The request. |
||
102 | * |
||
103 | * @return JsonResponse |
||
104 | * |
||
105 | * @throws NotFoundHttpException When the task could not be found. |
||
106 | * |
||
107 | * @ApiDoc( |
||
108 | * section="tasks", |
||
109 | * statusCodes = { |
||
110 | * 200 = "When everything worked out ok" |
||
111 | * }, |
||
112 | * authentication = true, |
||
113 | * authenticationRoles = { |
||
114 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
115 | * }, |
||
116 | * filters = { |
||
117 | * { |
||
118 | * "name"="offset", |
||
119 | * "dataType" = "int", |
||
120 | * "description"="If present, the output will be returned from the given byte offset." |
||
121 | * } |
||
122 | * } |
||
123 | * ) |
||
124 | * @ApiDescription( |
||
125 | * response={ |
||
126 | * "status" = { |
||
127 | * "dataType" = "string", |
||
128 | * "description" = "OK on success" |
||
129 | * }, |
||
130 | * "task" = { |
||
131 | * "id" = { |
||
132 | * "dataType" = "string", |
||
133 | * "description" = "The task id." |
||
134 | * }, |
||
135 | * "status" = { |
||
136 | * "dataType" = "string", |
||
137 | * "description" = "The task status." |
||
138 | * }, |
||
139 | * "type" = { |
||
140 | * "dataType" = "string", |
||
141 | * "description" = "The type of the task." |
||
142 | * }, |
||
143 | * "created_at" = { |
||
144 | * "dataType" = "string", |
||
145 | * "description" = "The date the task was created in ISO 8601 format." |
||
146 | * }, |
||
147 | * "output" = { |
||
148 | * "dataType" = "string", |
||
149 | * "description" = "The command line output of the task." |
||
150 | * } |
||
151 | * } |
||
152 | * ) |
||
153 | */ |
||
154 | public function getTaskAction($taskId, Request $request) |
||
170 | |||
171 | /** |
||
172 | * Queue a task in the list. |
||
173 | * |
||
174 | * @param Request $request The request. |
||
175 | * |
||
176 | * @return JsonResponse |
||
177 | * |
||
178 | * @throws NotAcceptableHttpException When the payload is invalid. |
||
179 | * |
||
180 | * @ApiDoc( |
||
181 | * section="tasks", |
||
182 | * statusCodes = { |
||
183 | * 201 = "When everything worked out ok" |
||
184 | * }, |
||
185 | * authentication = true, |
||
186 | * authenticationRoles = { |
||
187 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
188 | * }, |
||
189 | * ) |
||
190 | * @ApiDescription( |
||
191 | * response={ |
||
192 | * "status" = { |
||
193 | * "dataType" = "string", |
||
194 | * "description" = "OK on success" |
||
195 | * }, |
||
196 | * "task" = { |
||
197 | * "id" = { |
||
198 | * "dataType" = "string", |
||
199 | * "description" = "The task id." |
||
200 | * }, |
||
201 | * "status" = { |
||
202 | * "dataType" = "string", |
||
203 | * "description" = "The task status." |
||
204 | * }, |
||
205 | * "type" = { |
||
206 | * "dataType" = "string", |
||
207 | * "description" = "The type of the task." |
||
208 | * }, |
||
209 | * "created_at" = { |
||
210 | * "dataType" = "string", |
||
211 | * "description" = "The date the task was created in ISO 8601 format." |
||
212 | * }, |
||
213 | * "output" = { |
||
214 | * "dataType" = "string", |
||
215 | * "description" = "The command line output of the task." |
||
216 | * } |
||
217 | * } |
||
218 | * ) |
||
219 | */ |
||
220 | public function addTaskAction(Request $request) |
||
244 | |||
245 | /** |
||
246 | * Remove a task from the list. |
||
247 | * |
||
248 | * @param string $taskId The id of the task to remove. |
||
249 | * |
||
250 | * @return JsonResponse |
||
251 | * |
||
252 | * @throws NotFoundHttpException When the given task could not be found. |
||
253 | * @throws NotAcceptableHttpException When trying to delete a running task. |
||
254 | * |
||
255 | * @ApiDoc( |
||
256 | * section="tasks", |
||
257 | * statusCodes = { |
||
258 | * 200 = "When everything worked out ok" |
||
259 | * }, |
||
260 | * authentication = true, |
||
261 | * authenticationRoles = { |
||
262 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
263 | * }, |
||
264 | * ) |
||
265 | * @ApiDescription( |
||
266 | * response={ |
||
267 | * "status" = { |
||
268 | * "dataType" = "string", |
||
269 | * "description" = "OK on success" |
||
270 | * } |
||
271 | * } |
||
272 | * ) |
||
273 | */ |
||
274 | public function deleteTaskAction($taskId) |
||
296 | |||
297 | /** |
||
298 | * Starts the next pending task if any. |
||
299 | * |
||
300 | * @return JsonResponse |
||
301 | * |
||
302 | * @throws NotFoundHttpException When no task could be found. |
||
303 | * @throws NotAcceptableHttpException When a task is already running and holds the lock. |
||
304 | * |
||
305 | * @ApiDoc( |
||
306 | * section="tasks", |
||
307 | * statusCodes = { |
||
308 | * 200 = "When everything worked out ok", |
||
309 | * 404 = "When no pending task has been found", |
||
310 | * 406 = "When another task is still running" |
||
311 | * }, |
||
312 | * authentication = true, |
||
313 | * authenticationRoles = { |
||
314 | * "ROLE_MANIPULATE_REQUIREMENTS" |
||
315 | * }, |
||
316 | * ) |
||
317 | * @ApiDescription( |
||
318 | * response={ |
||
319 | * "status" = { |
||
320 | * "dataType" = "string", |
||
321 | * "description" = "OK on success" |
||
322 | * }, |
||
323 | * "task" = { |
||
324 | * "id" = { |
||
325 | * "dataType" = "string", |
||
326 | * "description" = "The task id." |
||
327 | * }, |
||
328 | * "status" = { |
||
329 | * "dataType" = "string", |
||
330 | * "description" = "The task status." |
||
331 | * }, |
||
332 | * "type" = { |
||
333 | * "dataType" = "string", |
||
334 | * "description" = "The type of the task." |
||
335 | * }, |
||
336 | * "created_at" = { |
||
337 | * "dataType" = "string", |
||
338 | * "description" = "The date the task was created in ISO 8601 format." |
||
339 | * }, |
||
340 | * "output" = { |
||
341 | * "dataType" = "string", |
||
342 | * "description" = "The command line output of the task." |
||
343 | * } |
||
344 | * } |
||
345 | * ) |
||
346 | */ |
||
347 | public function runAction() |
||
377 | |||
378 | /** |
||
379 | * Spawn a detached process for a task. |
||
380 | * |
||
381 | * @param Task $task The task to spawn a process for. |
||
382 | * |
||
383 | * @return void |
||
384 | * |
||
385 | * @throws \RuntimeException When the task could not be started. |
||
386 | */ |
||
387 | private function spawn(Task $task) |
||
422 | |||
423 | /** |
||
424 | * Convert a task to an array. |
||
425 | * |
||
426 | * @param Task $task |
||
427 | * @param null $outputOffset |
||
428 | * |
||
429 | * @return array |
||
430 | */ |
||
431 | private function convertTaskToArray(Task $task, $outputOffset = null) |
||
441 | |||
442 | /** |
||
443 | * Create a JsonResponse based on an array of tasks. |
||
444 | * |
||
445 | * @param Task[] $tasks |
||
446 | * @param string $status |
||
447 | * @param int $httpStatus |
||
448 | * |
||
449 | * @return JsonResponse |
||
450 | */ |
||
451 | private function createJsonResponse(array $tasks, $status = 'OK', $httpStatus = JsonResponse::HTTP_OK) |
||
462 | } |
||
463 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.