45 lines
1.7 KiB
Ruby
45 lines
1.7 KiB
Ruby
module HealthCheck
|
|
class Engine < ::Rails::Engine
|
|
initializer "health_check" do
|
|
Rails.application.config.to_prepare do
|
|
OrbitApp.registration "HealthCheck", :type => "ModuleApp" do
|
|
module_label "health_check.health_check"
|
|
base_url File.expand_path File.dirname(__FILE__)
|
|
|
|
authorizable
|
|
|
|
side_bar do
|
|
head_label_i18n 'health_check', :icon_class=>"icons-cycle"
|
|
available_for "users"
|
|
active_for_controllers (['admin/health_check_monitors'])
|
|
head_link_path "admin_health_check_monitors_path"
|
|
|
|
context_link 'list_',
|
|
:link_path=>"admin_health_check_monitors_path" ,
|
|
:priority=>1,
|
|
:active_for_action=>{'admin/health_check_monitors'=>'index'},
|
|
:available_for => 'users'
|
|
|
|
context_link 'new_',
|
|
:link_path=>"new_admin_health_check_monitor_path" ,
|
|
:priority=>2,
|
|
:active_for_action=>{'admin/health_check_monitors'=>'new'},
|
|
:available_for => 'sub_managers'
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# 自動檢測:用核心的 CronWorker 每分鐘叫一次,不使用 crontab
|
|
config.after_initialize do
|
|
if ENV['worker_num'] == '0' && File.basename($0) != 'rake' && !defined?(Rails::Console)
|
|
begin
|
|
CronWorker.cron_every_minute(HealthCheckMonitor.method(:run_due_checks))
|
|
rescue => e
|
|
Rails.logger.error("[health_check] CronWorker 啟動失敗: #{e}")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|