-
-
Save terjesb/1988056 to your computer and use it in GitHub Desktop.
Kestrel Producer
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 | |
/** | |
* 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