Files
dev-chiefworks f76abffdcd first commit
2022-05-31 16:21:53 -04:00

56 lines
1.3 KiB
PHP

<?php
class GearmanForClient
{
static $instances = array();
/**
* Fetch (and create if needed) an instance of this logger.
*
* @param string $server
* @param int $port
* @param string $queue
* @return self
*/
public static function getInstance($server = '127.0.0.1', $port = 4730, $queue = 'log')
{
$hash = $queue . $server . $port;
if (!array_key_exists($hash, self::$instances)) {
self::$instances[$hash] = new self($queue, $server, $port);
}
return self::$instances[$hash];
}
/** @var GearmanClient */
private $gmc;
/** @var string */
private $queue;
public function __construct($queue, $server, $port)
{
$this->gmc = new GearmanClient();
$this->queue = $queue;
$this->gmc->addServer($server, $port);
}
/**
* Fetch data from the api weather
* @param mixed $data
*/
public function fetchApiData($data)
{
$this->gmc->doBackground('fetchApiData', json_encode($data));
}
/**
* insert trip weather with existing weather data
* @param mixed $data
*/
public function processExistingWeatherData($data)
{
$this->gmc->doBackground('processExistingWeatherDataWorker', json_encode($data));
}
}