Files
terminus/app/aspects/firmware/poller.rb
T
Brooke Kuhlmann ea23e24172 Added poller disablement via settings
Necessary to disable pollers, if desired. Can be handy for deployment purposes should you not want these pollers to run and only have access to the environment variables.

Issue: 187
Milestone: minor
2025-07-31 09:33:13 -06:00

44 lines
1.0 KiB
Ruby

# frozen_string_literal: true
require "dry/monads"
require "initable"
module Terminus
module Aspects
module Firmware
# Polls the Core Firmware API on a scheduled interval for new firmware versions.
class Poller
include Deps[:settings, "aspects.firmware.synchronizer"]
include Initable[kernel: Kernel]
include Dry::Monads[:result]
# Seconds equates to six hours (60 * 60 * 6).
def call seconds: 21_600
watch_for_shudown
keep_alive seconds
end
private
def watch_for_shudown
kernel.trap "INT" do
kernel.puts "Gracefully shutting down firmware polling..."
kernel.exit
end
end
def keep_alive seconds
kernel.loop do
sync_or_skip
kernel.sleep seconds
end
end
def sync_or_skip
settings.firmware_poller ? synchronizer.call : kernel.puts("Firmware polling disabled.")
end
end
end
end
end