Compare commits

..

No commits in common. "a479f5da7c95b39d090f37cc0620c19a46f6f57f" and "578f41c212c47839ec163b86eb35b08bc06968e1" have entirely different histories.

7 changed files with 15 additions and 44 deletions

View File

@ -1,17 +1,6 @@
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

View File

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

View File

@ -7,8 +7,9 @@
<%= flash[:alert] %>
</div>
<% end %>
<div class="flex flex-col h-full divide-y divide-border-table-border">
<div class="flex-1 overflow-y-auto p-4 space-y-4">
<div class="flex-1 overflow-y-auto p-4">
<table class="base-table">
<thead>
<tr>
@ -25,21 +26,6 @@
<% end %>
</tbody>
</table>
<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>
</div>
</div>
<div class="flex p-4">
<%= link_to "수정", "/modbus/schedule_edit", class: "btn bg-default-slate" %>

View File

@ -1,4 +1,4 @@
<%= form_with url: schedule_edit_update_modbus_index_path, method: :post, class: 'flex flex-col h-full divide-y divide-border-table-border' do %>
<%= form_with url: "/modbus/schedule_edit_update", method: :post, class: 'flex flex-col h-full divide-y divide-border-table-border' do %>
<div class="flex-1 overflow-y-auto p-4">
<table class="base-table">
<thead>

View File

@ -1,5 +1,3 @@
$modbus_polling_threads ||= []
Rails.application.config.after_initialize do
Modbus::PollingService.start
end

View File

@ -14,8 +14,9 @@ Rails.application.routes.draw do
resources :modbus do
collection do
post "start"
post "stop"
get "start"
get "stop"
get "status"
get "schedule_edit"
post "schedule_edit_update"
end

View File

@ -8,6 +8,6 @@
# MovieGenre.find_or_create_by!(name: genre_name)
# end
(0..23).each do | h |
Schedule.create!(hour: h, temperature: 15.0)
(0..23).each_with_index do |h, index|
Schedule.create!(hour: h, temperature: index)
end