Преглед изворни кода

Adding Method to Request Job Status

Denis Zunke пре 11 година
родитељ
комит
be4773cb5a
2 измењених фајлова са 23 додато и 0 уклоњено
  1. 7 0
      README.md
  2. 16 0
      Service/GearmanClient.php

+ 7 - 0
README.md

@@ -486,6 +486,13 @@ You can request a Job by using the gearman client.
 * addTaskLowBackground: Add a low priority background task to be run in parallel
 * addTaskLowBackground: Add a low priority background task to be run in parallel
 * runTasks: Run a list of tasks in parallel
 * runTasks: Run a list of tasks in parallel
 
 
+## Request Job Status
+
+With the Handle given if requesting a job you can request the status of the job. The Method gives a boolean.
+
+    $result = $gearman
+        ->jobIsRunning($result);
+
 # Kernel Events
 # Kernel Events
 
 
 GearmanBundle transforms Gearman callbacks to Symfony2 kernel events.
 GearmanBundle transforms Gearman callbacks to Symfony2 kernel events.

+ 16 - 0
Service/GearmanClient.php

@@ -546,4 +546,20 @@ class GearmanClient extends AbstractGearmanService
 
 
         return $gearmanClient->runTasks();
         return $gearmanClient->runTasks();
     }
     }
+
+    /**
+     * Fetches the Status of a special Job. You need the Job handle for the Task you want to check.
+     * As long as the Job is known by the Gearmen-Servers it will return a true
+     *
+     * @param string $backgroundId the job handle string
+     * @return bool
+     */
+    public function jobIsRunning($backgroundId)
+    {
+        $gearmanClient = new \GearmanClient();
+        $this->assignServers($gearmanClient);
+        $statusData = $gearmanClient->jobStatus($backgroundId);
+
+        return isset($statusData[0]) && $statusData[0];
+    }
 }
 }