[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: SyncJob: improve job execution

git at icinga.org git at icinga.org
Tue Jun 7 15:59:13 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed May 25 11:46:27 2016 +0200

SyncJob: improve job execution

---

 library/Director/Job/SyncJob.php |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/library/Director/Job/SyncJob.php b/library/Director/Job/SyncJob.php
index aa0cb55..8c36983 100644
--- a/library/Director/Job/SyncJob.php
+++ b/library/Director/Job/SyncJob.php
@@ -13,20 +13,24 @@ class SyncJob extends JobHook
 
     public function run()
     {
-        if ($this->getSetting('apply_changes') === 'y') {
-            $this->syncRule()->applyChanges();
+        $db = $this->db();
+        $id = $this->getSetting('rule_id');
+        if ($id === '__ALL__') {
+            foreach (SyncRule::loadAll($db) as $rule) {
+                $this->runForRule($rule);
+            }
         } else {
-            $this->syncRule()->checkForChanges();
+            $this->runForRule(SyncRule::load($id, $db));
         }
     }
 
-    protected function syncRule()
+    protected function runForRule(SyncRule $rule)
     {
-        if ($this->rule === null) {
-            $this->rule = SyncRule::load($this->getSetting('rule_id'), $this->db());
+        if ($this->getSetting('apply_changes') === 'y') {
+            $rule->applyChanges();
+        } else {
+            $rule->checkForChanges();
         }
-
-        return $this->rule;
     }
 
     public static function getDescription(QuickForm $form)
@@ -88,8 +92,4 @@ class SyncJob extends JobHook
             '__ALL__' => $form->translate('Run all rules at once')
         ) + $res;
     }
-
-    public function isPending()
-    {
-    }
 }



More information about the icinga-checkins mailing list