Skip to content

Instantly share code, notes, and snippets.

@terjesb
Forked from shupp/EC_Producer.php
Created March 6, 2012 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terjesb/1988056 to your computer and use it in GitHub Desktop.
Save terjesb/1988056 to your computer and use it in GitHub Desktop.
Kestrel Producer
<?php
/**
* Interface for adding jobs to a queue server
*
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2010-2011 Empower Campaigns
*/
class EC_Producer
{
/**
* Adds a job onto a queue
*
* @param string $queue The queue name to add a job to
* @param string $jobName The job name for the consumer to run
* @param mixed $data Optional additional data to pass to the job
*
* @return bool
*/
public function addJob($queue, $jobName, $data = null)
{
$item = array(
'instance' => EC::getCurrentInstanceName(),
'jobName' => $jobName
);
if ($data !== null) {
$item['data'] = $data;
}
// Namespace queue with project
$queue = 'enterprise_' . $queue;
$client = $this->_getKestrelClient();
return $client->set($queue, $item);
}
// @codeCoverageIgnoreStart
/**
* Gets a single instance of EC_KestrelClient. Abstracted for testing.
*
* @return void
*/
protected function _getKestrelClient()
{
if (APPLICATION_ENV === 'testing') {
throw new Exception(__METHOD__ . ' was not mocked when testing');
}
static $client = null;
if ($client === null) {
$host = EC::getConfigOption('kestrel.host');
$port = EC::getConfigOption('kestrel.port');
$client = new EC_KestrelClient($host, $port);
}
return $client;
}
// @codeCoverageIgnoreEnd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment