Created
May 27, 2013 14:40
-
-
Save bakura10/5657404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace SlmQueue\Controller; | |
use SlmQueue\Controller\Exception\WorkerProcessException; | |
use SlmQueue\Exception\SlmQueueExceptionInterface; | |
use SlmQueue\Worker\WorkerInterface; | |
use Zend\Mvc\Controller\AbstractActionController; | |
/** | |
* AbstractController | |
*/ | |
abstract class AbstractWorkerController extends AbstractActionController | |
{ | |
/** | |
* @var WorkerInterface | |
*/ | |
protected $worker; | |
public function __construct(WorkerInterface $worker) | |
{ | |
$this->worker = $worker; | |
} | |
/** | |
* Get options for worker | |
* | |
* @return array | |
*/ | |
abstract protected function getOptions(); | |
/** | |
* Get name of queue | |
* | |
* @return string | |
*/ | |
abstract protected function getQueueName(); | |
/** | |
* Process a queue | |
* | |
* @return string | |
* @throws WorkerProcessingException | |
*/ | |
public function processAction() | |
{ | |
$worker = $this->getWorker(); | |
$options = $this->getOptions(); | |
$queue = $this->getQueueName(); | |
try { | |
$result = $worker->processQueue($queue, $options); | |
} catch (SlmQueueExceptionInterface $e) { | |
throw new WorkerProcessException( | |
'Caught exception while processing queue', | |
$e->getCode(), $e | |
); | |
} | |
return sprintf( | |
"Finished worker for queue %s with %s jobs", | |
$queue, | |
$result | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment