@@ -37,6 +37,20 @@ class TaskQueueService
3737 */
3838 private $ defaultTube ;
3939
40+ /**
41+ * Log the worker output on success
42+ *
43+ * @var boolean
44+ */
45+ private $ logWorkerOutputOnSuccess ;
46+
47+ /**
48+ * Log the worker output on failure
49+ *
50+ * @var boolean
51+ */
52+ private $ logWorkerOutputOnFailure ;
53+
4054 /**
4155 * @var \Doctrine\ORM\EntityManager
4256 */
@@ -65,6 +79,8 @@ public function __construct(
6579 $ this ->entityManager = $ entityManager ;
6680 $ this ->taskRepo = $ this ->entityManager ->getRepository ('WebdevviePheanstalkTaskQueueBundle:Task ' );
6781 $ this ->defaultTube = $ params ['default_tube ' ];
82+ $ this ->logWorkerOutputOnSuccess = $ params ['log_worker_output_on_success ' ];
83+ $ this ->logWorkerOutputOnFailure = $ params ['log_worker_output_on_failure ' ];
6884 }
6985
7086 /**
@@ -232,11 +248,15 @@ public function reserveTask($tube = null)
232248 * Deletes a task from the queue
233249 *
234250 * @param WorkPackage $task
251+ * @param string $log
235252 * @throws TaskQueueServiceException
236253 * @return void
237254 */
238- public function markDone (WorkPackage $ task )
255+ public function markDone (WorkPackage $ task, $ log )
239256 {
257+ if ($ this ->logWorkerOutputOnSuccess ) {
258+ $ this ->updateTaskLog ($ task , $ log );
259+ }
240260 $ this ->updateTaskStatus ($ task , Task::STATUS_DONE );
241261 $ this ->beanstalk ->delete ($ task ->getPheanstalkJob ());
242262 }
@@ -245,15 +265,39 @@ public function markDone(WorkPackage $task)
245265 * Marks a job as failed and deletes it from the beanstalk tube
246266 *
247267 * @param WorkPackage $task
268+ * @param string $log
248269 * @throws TaskQueueServiceException
249270 * @return void
250271 */
251- public function markFailed (WorkPackage $ task )
272+ public function markFailed (WorkPackage $ task, $ log )
252273 {
274+ if ($ this ->logWorkerOutputOnFailure ) {
275+ $ this ->updateTaskLog ($ task , $ log );
276+ }
253277 $ this ->updateTaskStatus ($ task , Task::STATUS_FAILED );
254278 $ this ->beanstalk ->delete ($ task ->getPheanstalkJob ());
255279 }
256280
281+ /**
282+ * Writes the log to the Task entity
283+ *
284+ * @param WorkPackage $task
285+ * @param string $log
286+ * @return void
287+ * @throws TaskQueueServiceException
288+ */
289+ private function updateTaskLog (WorkPackage $ task , $ log )
290+ {
291+ $ taskEntity = $ task ->getTaskEntity ();
292+ if ($ taskEntity instanceof Task) {
293+ $ taskEntity ->setLog ($ log );
294+ //make sure it is stored...
295+ $ this ->entityManager ->flush ($ taskEntity );
296+ } else {
297+ throw new TaskQueueServiceException ("Entity is not of type Task " );
298+ }
299+ }
300+
257301 /**
258302 * Updates the task status
259303 *
0 commit comments