스케쥴러 시작/정기 기능 추가
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
class ModbusController < ApplicationController
|
||||
def index
|
||||
@schedule = Schedule.all
|
||||
@modbus_running = Modbus::PollingService.running?
|
||||
end
|
||||
|
||||
def start
|
||||
Modbus::PollingService.start
|
||||
redirect_to modbus_index_path
|
||||
end
|
||||
|
||||
def stop
|
||||
Modbus::PollingService.stop
|
||||
redirect_to modbus_index_path
|
||||
end
|
||||
|
||||
def schedule_edit
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<meta http-equiv="refresh" content="5">
|
||||
|
||||
<% if flash[:notice] %>
|
||||
<div class="mb-4 rounded bg-green-100 px-4 py-2 text-green-800 border border-green-300">
|
||||
<%= flash[:notice] %>
|
||||
@@ -15,4 +17,20 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= link_to "수정", "/modbus/schedule_edit", class: "btn btn-primary" %>
|
||||
<div class="py-4">
|
||||
<%= button_to "수정", schedule_edit_modbus_index_path, method: :get, class: "btn bg-primary" %>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-x-2">
|
||||
<%= button_to "스케쥴러 시작", start_modbus_index_path, method: :post, class: "btn bg-accept" %>
|
||||
<%= button_to "스케쥴러 정지", stop_modbus_index_path, method: :post, class: "btn bg-danger" %>
|
||||
</div>
|
||||
|
||||
<div class="py-4">
|
||||
<span class="font-semibold">스케쥴러 상태:</span>
|
||||
<% if @modbus_running %>
|
||||
<span class="text-accept font-bold">실행 중</span>
|
||||
<% else %>
|
||||
<span class="text-danger font-bold">정지됨</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= form_with url: "/modbus/schedule_edit_update", method: :post do %>
|
||||
<%= form_with url: schedule_edit_update_modbus_index_path, method: :post do %>
|
||||
<% @schedule.each do |s| %>
|
||||
<div class="flex justify-items-center gap-x-2 pb-2">
|
||||
<div><%= s.hour %>시</div>
|
||||
|
||||
Reference in New Issue
Block a user