|
@@ -26,6 +26,13 @@ use Mmoreram\GearmanBundle\Service\Abstracts\AbstractGearmanService;
|
|
*/
|
|
*/
|
|
class GearmanClient extends AbstractGearmanService
|
|
class GearmanClient extends AbstractGearmanService
|
|
{
|
|
{
|
|
|
|
+ /**
|
|
|
|
+ * @var \GearmanClient
|
|
|
|
+ *
|
|
|
|
+ * Gearman native client instance
|
|
|
|
+ */
|
|
|
|
+ protected $gearmanClient;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @var GearmanCallbacksDispatcher
|
|
* @var GearmanCallbacksDispatcher
|
|
*
|
|
*
|
|
@@ -75,6 +82,16 @@ class GearmanClient extends AbstractGearmanService
|
|
*/
|
|
*/
|
|
protected $returnCode;
|
|
protected $returnCode;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @return \GearmanClient
|
|
|
|
+ */
|
|
|
|
+ public function getNativeClient(){
|
|
|
|
+ if ($this->gearmanClient === null){
|
|
|
|
+ $this->gearmanClient = new \GearmanClient();
|
|
|
|
+ }
|
|
|
|
+ return $this->gearmanClient;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Init tasks structure
|
|
* Init tasks structure
|
|
*
|
|
*
|
|
@@ -229,12 +246,14 @@ class GearmanClient extends AbstractGearmanService
|
|
*/
|
|
*/
|
|
protected function doEnqueue(array $worker, $params, $method, $unique)
|
|
protected function doEnqueue(array $worker, $params, $method, $unique)
|
|
{
|
|
{
|
|
- $gearmanClient = new \GearmanClient();
|
|
|
|
|
|
+ $gearmanClient = $this->getNativeClient();
|
|
$this->assignServers($gearmanClient);
|
|
$this->assignServers($gearmanClient);
|
|
|
|
|
|
$result = $gearmanClient->$method($worker['job']['realCallableName'], $params, $unique);
|
|
$result = $gearmanClient->$method($worker['job']['realCallableName'], $params, $unique);
|
|
$this->returnCode = $gearmanClient->returnCode();
|
|
$this->returnCode = $gearmanClient->returnCode();
|
|
|
|
|
|
|
|
+ $this->gearmanClient = null;
|
|
|
|
+
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -426,12 +445,14 @@ class GearmanClient extends AbstractGearmanService
|
|
*/
|
|
*/
|
|
public function getJobStatus($idJob)
|
|
public function getJobStatus($idJob)
|
|
{
|
|
{
|
|
- $gearmanClient = new \GearmanClient();
|
|
|
|
|
|
+ $gearmanClient = $this->getNativeClient();
|
|
$this->assignServers($gearmanClient);
|
|
$this->assignServers($gearmanClient);
|
|
$statusData = $gearmanClient->jobStatus($idJob);
|
|
$statusData = $gearmanClient->jobStatus($idJob);
|
|
|
|
|
|
$jobStatus = new JobStatus($statusData);
|
|
$jobStatus = new JobStatus($statusData);
|
|
|
|
|
|
|
|
+ $this->gearmanClient = null;
|
|
|
|
+
|
|
return $jobStatus;
|
|
return $jobStatus;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -642,7 +663,7 @@ class GearmanClient extends AbstractGearmanService
|
|
*/
|
|
*/
|
|
public function runTasks()
|
|
public function runTasks()
|
|
{
|
|
{
|
|
- $gearmanClient = new \GearmanClient();
|
|
|
|
|
|
+ $gearmanClient = $this->getNativeClient();
|
|
$this->assignServers($gearmanClient);
|
|
$this->assignServers($gearmanClient);
|
|
|
|
|
|
if ($this->settings['callbacks']) {
|
|
if ($this->settings['callbacks']) {
|
|
@@ -669,6 +690,8 @@ class GearmanClient extends AbstractGearmanService
|
|
|
|
|
|
$this->initTaskStructure();
|
|
$this->initTaskStructure();
|
|
|
|
|
|
|
|
+ $this->gearmanClient = null;
|
|
|
|
+
|
|
return $gearmanClient->runTasks();
|
|
return $gearmanClient->runTasks();
|
|
}
|
|
}
|
|
}
|
|
}
|