[icinga-checkins] icinga.org: icingaweb2-module-director/master: JobsCommand: really run job , remove legacy logic

git at icinga.org git at icinga.org
Thu Jun 16 15:09:52 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: a0864e2240410bb1113812b12d1c4ffb1a3ffbe8
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=a0864e2240410bb1113812b12d1c4ffb1a3ffbe8

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Jun 16 14:41:02 2016 +0200

JobsCommand: really run job, remove legacy logic

---

 application/clicommands/JobsCommand.php |   85 ++++++++++---------------------
 1 file changed, 26 insertions(+), 59 deletions(-)

diff --git a/application/clicommands/JobsCommand.php b/application/clicommands/JobsCommand.php
index 08eaa4c..bd22571 100644
--- a/application/clicommands/JobsCommand.php
+++ b/application/clicommands/JobsCommand.php
@@ -3,92 +3,59 @@
 namespace Icinga\Module\Director\Clicommands;
 
 use Icinga\Module\Director\Cli\Command;
+use Icinga\Module\Director\Job\JobRunner;
 use Icinga\Module\Director\Objects\ImportSource;
 use Icinga\Module\Director\Objects\SyncRule;
 use Icinga\Module\Director\IcingaConfig\IcingaConfig;
 use Icinga\Module\Director\Import\Import;
 use Icinga\Module\Director\Import\Sync;
 use Icinga\Application\Benchmark;
+use Icinga\Application\Logger;
 use Exception;
 
 class JobsCommand extends Command
 {
     public function runAction()
     {
-        if ($this->hasBeenDisabled()) {
+        $job = $this->params->shift();
+        if ($job) {
+            echo "Running (theoretically) $job\n";
             return;
         }
 
-        $this->runScheduledImports()
-             ->runScheduledSyncs()
-             ->syncCoreStages()
-             ->runScheduledDeployments()
-             ;
-    }
-
-    public function renderconfigAction()
-    {
-        IcingaConfig::generate($this->db());
-    }
-
-    protected function hasBeenDisabled()
-    {
-        return $this->db()->getSetting('disable_all_jobs') === 'y';
+        if ($this->params->shift('once')) {
+            $this->runAllPendingJobs();
+        } else {
+            $this->runforever();
+        }
     }
 
-    protected function runScheduledImports()
+    protected function runforever()
     {
-        foreach (ImportSource::loadAll($this->db()) as $source) {
-            Benchmark::measure('Starting with import ' . $source->source_name);
-            try {
-
-                $import = new Import($source);
-                if ($import->providesChanges()) {
-                    printf('Import "%s" provides changes, triggering run... ', $source->source_name);
-                    Benchmark::measure('Found changes for ' . $source->source_name);
-                    if ($import->run()) {
-                        Benchmark::measure('Import succeeded for ' . $source->source_name);
-                        print "SUCCEEDED\n";
-                    }
-                }
-            } catch (Exception $e) {
-                echo $this->screen->colorize('ERROR: ' . $e->getMessage(), 'red') . "\n";
-                Benchmark::measure('FAILED');
-            }
+        while (true) {
+            $this->runAllPendingJobs();
+            sleep(2);
         }
-
-        return $this;
     }
 
-    protected function runScheduledSyncs()
+    protected function runAllPendingJobs()
     {
-        // TODO: import-triggered:
-        //      foreach $rule->involvedImports() -> if changedsince -> ... syncChangedRows
-
-        foreach (SyncRule::loadAll($this->db) as $rule) {
-            Benchmark::measure('Checking sync rule ' . $rule->rule_name);
-            $sync = new Sync($rule);
-            if ($sync->hasModifications()) {
-                printf('Sync rule "%s" provides changes, triggering sync... ', $rule->rule_name);
-                Benchmark::measure('Got modifications for sync rule ' . $rule->rule_name);
+        $jobs = new JobRunner($this->db());
 
-                if ($sync->apply()) {
-                    Benchmark::measure('Successfully synced rule ' . $rule->rule_name);
-                    print "SUCCEEDED\n";
-                }
+        try {
+            if ($this->hasBeenDisabled()) {
+                return;
             }
-        }
-
-        return $this;
-    }
 
-    protected function syncCoreStages()
-    {
-        return $this;
+            $jobs->runPendingJobs();
+        } catch (Exception $e) {
+            Logger::error('Director Job Error: ' . $e->getMessage());
+            sleep(10);
+        }
     }
 
-    protected function runScheduledDeployments()
+    protected function hasBeenDisabled()
     {
-        return $this;
+        return $this->db()->getSetting('disable_all_jobs') === 'y';
     }
 }



More information about the icinga-checkins mailing list