Browse Source

Merge pull request #116 from orolin/master

Added ::getReturnCode to GearmanClient
Marc Morera 11 years ago
parent
commit
bd15b47911
2 changed files with 24 additions and 1 deletions
  1. 3 0
      Resources/docs/client.rst
  2. 21 1
      Service/GearmanClient.php

+ 3 - 0
Resources/docs/client.rst

@@ -38,6 +38,8 @@ Request a job
     $result = $gearman
     $result = $gearman
         ->doJob('MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething', json_encode(array('value1')));
         ->doJob('MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething', json_encode(array('value1')));
 
 
+    $returnCode = $gearman->getReturnCode();
+
 - doJob: Call the job and wait for the result
 - doJob: Call the job and wait for the result
 - doNormalJob: Call the job and wait for the result ( Only newest gearman versions )
 - doNormalJob: Call the job and wait for the result ( Only newest gearman versions )
 - doHighJob: Call the job and wait for the result on High Preference
 - doHighJob: Call the job and wait for the result on High Preference
@@ -50,6 +52,7 @@ Request a job
     - It receives a job handle for the submitted job
     - It receives a job handle for the submitted job
 - callJob: Call the job with default method.
 - callJob: Call the job with default method.
     - Defined in settings, work annotations or the job annotations
     - Defined in settings, work annotations or the job annotations
+- getReturnCode: Retrieve the return code from the last requested job.
 
 
 Tasks
 Tasks
 ~~~~~
 ~~~~~

+ 21 - 1
Service/GearmanClient.php

@@ -68,6 +68,13 @@ class GearmanClient extends AbstractGearmanService
      */
      */
     protected $uniqueJobIdentifierGenerator;
     protected $uniqueJobIdentifierGenerator;
 
 
+    /**
+     * @var int
+     *
+     * Return code from internal client.
+     */
+    protected $returnCode;
+
     /**
     /**
      * Init tasks structure
      * Init tasks structure
      *
      *
@@ -225,7 +232,10 @@ class GearmanClient extends AbstractGearmanService
         $gearmanClient = new \GearmanClient();
         $gearmanClient = new \GearmanClient();
         $this->assignServers($gearmanClient);
         $this->assignServers($gearmanClient);
 
 
-        return $gearmanClient->$method($worker['job']['realCallableName'], $params, $unique);
+        $result = $gearmanClient->$method($worker['job']['realCallableName'], $params, $unique);
+        $this->returnCode = $gearmanClient->returnCode();
+
+        return $result;
     }
     }
 
 
     /**
     /**
@@ -425,6 +435,16 @@ class GearmanClient extends AbstractGearmanService
         return $jobStatus;
         return $jobStatus;
     }
     }
 
 
+    /**
+     * Gets the return code from the last run job.
+     *
+     * @return int
+     */
+    public function getReturnCode()
+    {
+        return $this->returnCode;
+    }
+
     /**
     /**
      * Task methods
      * Task methods
      */
      */