Rework hash building commands
authorCameron Ball <cameron@moodle.com>
Tue, 14 May 2019 05:23:28 +0000 (13:23 +0800)
committerCameron Ball <cameron@moodle.com>
Tue, 14 May 2019 05:23:28 +0000 (13:23 +0800)
src/gnb.php

index 1f9e155..453a577 100644 (file)
@@ -332,8 +332,8 @@ getTelegram()->addCommand(
 
 getTelegram()->addCommand(
     new class extends Command {
-        protected $name = 'hashgen';
-        protected $description = 'Generate the songs hash';
+        protected $name = 'updatehashes';
+        protected $description = 'Update the songs hash list (should be reasonably fast)';
 
         public function handle($arguments) {
             if (file_exists('/tmp/gnb.lock')) {
@@ -347,15 +347,41 @@ getTelegram()->addCommand(
             }
             $this->replyWithMessage(
                 [
-                    'text' => "Building songs hash list... This will take a while."
+                    'text' => "Updating songs hash list... This could take a while, hopefully not though."
                 ]
             );
             $chatid = getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id');
 
-            exec('/opt/hashgen.sh notify ' . $chatid . ' > /dev/null &');
+            exec('/opt/fasthashgen.sh notify ' . $chatid . ' > /dev/null &');
         }
     }
 );
 
+getTelegram()->addCommand(
+    new class extends Command {
+        protected $name = 'regeneratehashes';
+        protected $description = 'Completely regenerate the songs hash list';
+
+        public function handle($arguments) {
+            if (file_exists('/tmp/gnb.lock')) {
+                $this->replyWithMessage(
+                    [
+                        'text' => "Rebuild currently in progress, try again after it is complete."
+                    ]
+                );
+
+                return;
+            }
+            $this->replyWithMessage(
+                [
+                    'text' => "Rebuilding songs hash list... This will take a while."
+                ]
+            );
+            $chatid = getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id');
+
+            exec('/opt/hashgen.sh notify ' . $chatid . ' > /dev/null &');
+        }
+    }
+);
 
 getTelegram()->commandsHandler(true); //must come afterwards because lolzer