Class: RailsOpsDashboard::WorkersController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- RailsOpsDashboard::WorkersController
- Defined in:
- app/controllers/rails_ops_dashboard/workers_controller.rb
Constant Summary collapse
- PIDS =
Concurrent::Map.new
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
10 11 12 13 14 |
# File 'app/controllers/rails_ops_dashboard/workers_controller.rb', line 10 def index @workers = plugin_workers.map do |worker| worker.merge(status: worker_status(worker[:id])) end end |
#start ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/rails_ops_dashboard/workers_controller.rb', line 16 def start worker = plugin_workers.find { |w| w[:id] == params[:id] } return redirect_to workers_path(message: 'Worker not found', type: 'error') unless worker if worker_status(params[:id]) == :running return redirect_to workers_path(message: "#{worker[:name]} is already running", type: 'error') end pid = Process.spawn(worker[:command]) Process.detach(pid) PIDS[params[:id]] = pid redirect_to workers_path(message: "#{worker[:name]} started (PID: #{pid})", type: 'success') end |
#stop ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/rails_ops_dashboard/workers_controller.rb', line 31 def stop worker = plugin_workers.find { |w| w[:id] == params[:id] } return redirect_to workers_path(message: 'Worker not found', type: 'error') unless worker pid = PIDS.delete(params[:id]) return redirect_to workers_path(message: 'Worker not running', type: 'error') unless pid begin Process.kill('TERM', pid) rescue Errno::ESRCH # rubocop:disable Lint/SuppressedException end redirect_to workers_path(message: "Stop signal sent to #{worker[:name]}", type: 'success') end |