mirror of
https://github.com/usetrmnl/terminus.git
synced 2026-08-13 14:29:27 -07:00
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
44 lines
1.0 KiB
Ruby
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
|