Class: RailsOpsDashboard::SeedsController

Inherits:
BaseController
  • Object
show all
Includes:
BackgroundTaskRunner
Defined in:
app/controllers/rails_ops_dashboard/seeds_controller.rb

Constant Summary

Constants included from BackgroundTaskRunner

BackgroundTaskRunner::TASKS

Instance Method Summary collapse

Methods included from BackgroundTaskRunner

#run_in_background, #task_status

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/rails_ops_dashboard/seeds_controller.rb', line 11

def execute
  config = RailsOpsDashboard.configuration
  class_name = params[:class_name]

  unless class_name&.start_with?("#{config.seeds_base_class}::") && valid_seed?(class_name)
    return redirect_to seeds_path(message: 'Invalid seed class', type: 'error')
  end

  task_id = SecureRandom.hex(8)
  klass = class_name.constantize

  run_in_background(task_id, class_name) do
    config.seeds_executor.call(klass)
  end

  redirect_to seeds_path(message: "Started: #{class_name}", type: 'info', task_id: task_id)
rescue NameError, LoadError
  redirect_to seeds_path(message: "Class not found: #{class_name}", type: 'error')
end

#indexObject



7
8
9
# File 'app/controllers/rails_ops_dashboard/seeds_controller.rb', line 7

def index
  @seeds = discover_seeds
end

#statusObject



31
32
33
34
# File 'app/controllers/rails_ops_dashboard/seeds_controller.rb', line 31

def status
  task = task_status(params[:task_id])
  render json: task || { status: 'not_found' }
end