From 09c74de226f91d97fab09a6270bbab2956197813 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 17 Mar 2021 14:30:14 +0100 Subject: [rebootcontrol] Simplify some logic, improve scheduler --- modules-available/rebootcontrol/hooks/cron.inc.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'modules-available/rebootcontrol/hooks/cron.inc.php') diff --git a/modules-available/rebootcontrol/hooks/cron.inc.php b/modules-available/rebootcontrol/hooks/cron.inc.php index 5ae3b1c8..56446c49 100644 --- a/modules-available/rebootcontrol/hooks/cron.inc.php +++ b/modules-available/rebootcontrol/hooks/cron.inc.php @@ -12,25 +12,21 @@ if (in_array((int)date('G'), [6, 7, 9, 12, 15]) && in_array(date('i'), ['00', '0 // CRON for Scheduler $now = time(); -$res = Database::simpleQuery("SELECT * FROM reboot_scheduler WHERE nextexecution < :now", ['now' => $now]); +$res = Database::simpleQuery("SELECT s.locationid, s.action, s.nextexecution, s.options, l.openingtime + FROM reboot_scheduler s + INNER JOIN location l USING (locationid) + WHERE s.nextexecution <= :now", ['now' => $now]); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $options = json_decode($row['options'], true); // Calculate next_execution for the event. - $location = Database::queryFirst("SELECT openingtime FROM `location` - WHERE locationid = :lid", ['lid' => $row['locationid']]); - Scheduler::updateSchedule($row['locationid'], $options, $location['openingtime']); + Scheduler::updateSchedule($row['locationid'], $options, $row['openingtime']); if ($row['nextexecution'] + 1200 < $now) continue; - $machinedb = Database::simpleQuery("SELECT machineuuid, clientip, macaddr, locationid FROM machine + $machines = Database::queryAll("SELECT machineuuid, clientip, macaddr, locationid FROM machine WHERE locationid = :locid", ['locid' => $row['locationid']]); - $machines = []; - while ($machine = $machinedb->fetch(PDO::FETCH_ASSOC)) { - settype($machine['locationid'], 'int'); - $machines[] = $machine; - } if ($row['action'] === 'sd') { RebootControl::execute($machines, RebootControl::SHUTDOWN, 0); } elseif ($row['action'] === 'wol') { -- cgit v1.2.3-55-g7522