Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created May 27, 2013 14:40
Show Gist options
  • Save bakura10/5657404 to your computer and use it in GitHub Desktop.
Save bakura10/5657404 to your computer and use it in GitHub Desktop.
<?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