From 0e7e1dcfaef5300060f8d132021da56aa4e87632 Mon Sep 17 00:00:00 2001 From: cam Date: Wed, 16 Oct 2024 14:47:40 +1300 Subject: [PATCH] Reduce local salt calls --- _release/tc2-hat-attiny.service | 1 + cmd/tc2-hat-attiny/main.go | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/_release/tc2-hat-attiny.service b/_release/tc2-hat-attiny.service index 5832710..f0363c7 100644 --- a/_release/tc2-hat-attiny.service +++ b/_release/tc2-hat-attiny.service @@ -2,6 +2,7 @@ [Unit] Description=Cacophony Project ATtiny controller After=multi-user.target +ConditionPathExists=/etc/salt/minion_id [Service] Type=simple diff --git a/cmd/tc2-hat-attiny/main.go b/cmd/tc2-hat-attiny/main.go index 48795e4..501c329 100644 --- a/cmd/tc2-hat-attiny/main.go +++ b/cmd/tc2-hat-attiny/main.go @@ -159,11 +159,6 @@ func runMain() error { onReason = fmt.Sprintf("Staying on because camera has been requested to stay on for %s", durToStr(waitDuration)) } - if waitDuration < saltCommandWaitDuration && shouldStayOnForSalt() { - waitDuration = saltCommandWaitDuration - onReason = "Staying on because salt command is running" - } - // Check if the RP2040 wants the RPi to stay on if waitDuration <= time.Duration(0) { val, err := attiny.readRegister(rp2040PiPowerCtrlReg) @@ -176,6 +171,12 @@ func runMain() error { } } + // Checking if a salt command is running should only be done if needed + if waitDuration < time.Duration(0) && shouldStayOnForSalt() { + waitDuration = saltCommandWaitDuration + onReason = "Staying on because salt command is running" + } + if waitDuration <= time.Duration(0) { stayOnLock.Lock() for process, maxTime := range stayOnForProcess {