add command to shut down a worker
authorChristian Weiske <cweiske@cweiske.de>
Thu, 10 Nov 2016 14:13:51 +0000 (15:13 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 10 Nov 2016 14:13:51 +0000 (15:13 +0100)
bin/phinde-worker.php
bin/stop-worker.php [new file with mode: 0755]

index 1e94535b1d5dc86f208a7113a5f6cbbe9c1a1cb6..9f8c35aa9ff95f9e3cca309150f33349c4e3317b 100755 (executable)
@@ -23,6 +23,15 @@ $gmworker->addFunction(
     }
 );
 
     }
 );
 
+$gmworker->addFunction(
+    $GLOBALS['phinde']['queuePrefix'] . 'phinde_quit',
+    function(\GearmanJob $job) {
+        echo "Got exit job\n";
+        $job->sendComplete('');
+        exit(0);
+    }
+);
+
 while ($gmworker->work()) {
     if ($gmworker->returnCode() != GEARMAN_SUCCESS) {
         echo 'Error running job: ' . $gmworker->returnCode() . "\n";
 while ($gmworker->work()) {
     if ($gmworker->returnCode() != GEARMAN_SUCCESS) {
         echo 'Error running job: ' . $gmworker->returnCode() . "\n";
diff --git a/bin/stop-worker.php b/bin/stop-worker.php
new file mode 100755 (executable)
index 0000000..48a2fe1
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/env php
+<?php
+//stop a single running worker
+namespace phinde;
+require_once __DIR__ . '/../src/init.php';
+
+$gmclient = new \GearmanClient();
+$gmclient->addServer('127.0.0.1');
+$gmclient->doHigh(
+    $GLOBALS['phinde']['queuePrefix'] . 'phinde_quit', 'none'
+);
+?>