diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-06-05 14:19:07 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-06-05 14:19:07 -0400 |
commit | a08339059b06bcfb673b13a380b6f199abfb5983 (patch) | |
tree | 81638ec619684f04d9b5676bea1f73e1a2197cd1 /app/Core/Queue | |
parent | f48e5456312ddb366f9b623cd97b0e740fe99d9e (diff) |
Improve background workers
Diffstat (limited to 'app/Core/Queue')
-rw-r--r-- | app/Core/Queue/JobHandler.php | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/app/Core/Queue/JobHandler.php b/app/Core/Queue/JobHandler.php index a2c4a2c7..f8736cce 100644 --- a/app/Core/Queue/JobHandler.php +++ b/app/Core/Queue/JobHandler.php @@ -26,6 +26,7 @@ class JobHandler extends Base return new Job(array( 'class' => get_class($job), 'params' => $job->getJobParams(), + 'user_id' => $this->userSession->getId(), )); } @@ -39,12 +40,30 @@ class JobHandler extends Base { $payload = $job->getBody(); $className = $payload['class']; + $this->prepareJobSession($payload['user_id']); if (DEBUG) { - $this->logger->debug(__METHOD__.' Received job => '.$className); + $this->logger->debug(__METHOD__.' Received job => '.$className.' ('.getmypid().')'); } $worker = new $className($this->container); call_user_func_array(array($worker, 'execute'), $payload['params']); } + + /** + * Create the session for the job + * + * @access protected + * @param integer $user_id + */ + protected function prepareJobSession($user_id) + { + $session = array(); + $this->sessionStorage->setStorage($session); + + if ($user_id > 0) { + $user = $this->userModel->getById($user_id); + $this->userSession->initialize($user); + } + } } |