스케쥴러 시작/정기 기능 추가

This commit is contained in:
2025-04-17 06:42:51 +09:00
parent 4b9c59b6e0
commit f9cdd77e7a
7 changed files with 47 additions and 14 deletions

View File

@@ -2,9 +2,9 @@ module Modbus
class PollingService
class << self
def start
return if @thread&.alive?
return if $modbus_polling_threads.any?(&:alive?)
@thread = Thread.new do
thread = Thread.new do
puts "[#{Time.current}] Modbus polling service 시작됨"
last_logged_hour = nil
loop do
@@ -32,14 +32,17 @@ module Modbus
end
end
end
$modbus_polling_threads << thread
end
def stop
if @thread
@thread.exit
@thread = nil
puts "[#{Time.now}] Modbus polling service 중지됨"
end
$modbus_polling_threads.each { |t| t.kill if t.alive? }
$modbus_polling_threads.clear
puts "[#{Time.now}] Modbus polling service 중지됨"
end
def running?
$modbus_polling_threads.any?(&:alive?)
end
end
end