Compare commits

...

3 Commits

Author SHA1 Message Date
RubyOn cb19bc990d time.current -> time.now 로 전부 수정 2025-04-20 08:51:51 +09:00
RubyOn a958915d41 rufus-scheduler 수정 2025-04-19 06:38:46 +09:00
RubyOn 9ca6e10ac1 rufus-scheduler 수정 2025-04-19 06:37:09 +09:00
6 changed files with 42 additions and 10 deletions

12
.idea/dataSources.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="development.sqlite3" uuid="d3ab71a5-ebb0-4573-9e48-bc4bd013b015">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/storage/development.sqlite3</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

6
.idea/sqldialects.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/app/controllers/schedules_controller.rb" dialect="GenericSQL" />
</component>
</project>

View File

@ -30,6 +30,14 @@ class SchedulesController < ApplicationController
end end
end end
def reset
Schedule.delete_all
ActiveRecord::Base.connection.execute("DELETE FROM sqlite_sequence WHERE name='schedules'")
Rails.application.load_seed
redirect_to schedules_path, notice: "스케줄이 초기화되었습니다."
end
def schedule_edit def schedule_edit
@schedule = Schedule.order(:hour, :minute) @schedule = Schedule.order(:hour, :minute)
end end

View File

@ -5,10 +5,10 @@ module Modbus
class PollingService class PollingService
class << self class << self
def start def start
return if defined?(@scheduler) && @scheduler.jobs.any? return if @scheduler
puts "[#{Time.current}] Modbus polling service 시작됨 (Rufus)" puts "[#{Time.now}] Modbus polling service 시작됨 (Rufus)"
@scheduler = Rufus::Scheduler.new @scheduler ||= Rufus::Scheduler.new
@scheduler.cron "0 * * * * *" do @scheduler.cron "0 * * * * *" do
now = Time.now now = Time.now
@ -22,14 +22,15 @@ module Modbus
def stop def stop
if defined?(@scheduler) if defined?(@scheduler)
@scheduler.shutdown(:kill) @scheduler.shutdown(:kill)
puts "[#{Time.current}] Modbus polling service 중지됨" @scheduler = nil
puts "[#{Time.now}] Modbus polling service 중지됨"
else else
puts "[#{Time.current}] Scheduler 인스턴스 없음" puts "[#{Time.now}] Scheduler 인스턴스 없음"
end end
end end
def running? def running?
defined?(@scheduler) && @scheduler.jobs.any? @scheduler
end end
private private
@ -51,7 +52,7 @@ module Modbus
if system("ruby", path.to_s, arg) if system("ruby", path.to_s, arg)
puts success_msg puts success_msg
else else
puts "[#{Time.current}] #{file} 실행 실패 (args: #{arg})" puts "[#{Time.now}] #{file} 실행 실패 (args: #{arg})"
end end
end end
end end

View File

@ -39,9 +39,15 @@
<%= submit_tag "업데이트", class: "btn bg-primary" %> <%= submit_tag "업데이트", class: "btn bg-primary" %>
</div> </div>
<% end %> <% end %>
<div class="flex p-4">
<%= button_to "초기화", reset_schedules_path,
method: :post,
data: { turbo_confirm: "정말 초기화하시겠습니까? 모든 스케줄 데이터가 삭제됩니다." },
class: "btn bg-danger" %>
</div>
<div class="flex p-4"> <div class="flex p-4">
<%= button_to "추가하기", open_modals_path(type: "add_schedule"), <%= button_to "추가하기", open_modals_path(type: "add_schedule"),
class: "btn btn-default", class: "btn bg-default-slate",
data: { data: {
turbo_method: :post, turbo_method: :post,
turbo_frame: "modals" turbo_frame: "modals"

View File

@ -15,6 +15,7 @@ Rails.application.routes.draw do
resources :schedules do resources :schedules do
collection do collection do
post "reset"
get "schedule_edit" get "schedule_edit"
post "schedule_edit_update" post "schedule_edit_update"
end end
@ -24,8 +25,6 @@ Rails.application.routes.draw do
collection do collection do
post "start" post "start"
post "stop" post "stop"
get "schedule_edit"
post "schedule_edit_update"
end end
end end