Class: SolidQueueWeb::DashboardController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solid_queue_web/dashboard_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::PERIOD_DURATIONS

Instance Method Summary collapse

Instance Method Details

#discard_all_blockedObject



36
37
38
39
40
41
42
# File 'app/controllers/solid_queue_web/dashboard_controller.rb', line 36

def discard_all_blocked
  jobs = SolidQueue::BlockedExecution.includes(:job).map(&:job)
  SolidQueue::BlockedExecution.discard_all_from_jobs(jobs)
  redirect_to root_path, notice: "#{jobs.size} blocked #{"job".pluralize(jobs.size)} discarded."
rescue => e
  redirect_to root_path, alert: "Could not discard blocked jobs: #{e.message}"
end

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/solid_queue_web/dashboard_controller.rb', line 3

def index
  @stats = {
    ready:     SolidQueue::ReadyExecution.count,
    scheduled: SolidQueue::ScheduledExecution.count,
    claimed:   SolidQueue::ClaimedExecution.count,
    failed:    SolidQueue::FailedExecution.count,
    blocked:   SolidQueue::BlockedExecution.count,
    queues:    SolidQueue::Job.select(:queue_name).distinct.count,
    processes: SolidQueue::Process.count,
    recurring: SolidQueue::RecurringTask.count
  }

  now = Time.current
  finished_times = SolidQueue::Job.where(finished_at: 24.hours.ago..now).pluck(:finished_at)
  @throughput = {
    completed_1h:  finished_times.count { |t| t >= 1.hour.ago },
    completed_24h: finished_times.size
  }
  @sparkline = 12.times.map do |i|
    from = (12 - i).hours.ago
    to   = i == 11 ? now : (11 - i).hours.ago
    finished_times.count { |t| t >= from && t < to }
  end
end

#retry_all_failedObject



28
29
30
31
32
33
34
# File 'app/controllers/solid_queue_web/dashboard_controller.rb', line 28

def retry_all_failed
  jobs = SolidQueue::FailedExecution.includes(:job).map(&:job)
  SolidQueue::FailedExecution.retry_all(jobs)
  redirect_to root_path, notice: "#{jobs.size} failed #{"job".pluralize(jobs.size)} queued for retry."
rescue => e
  redirect_to root_path, alert: "Could not retry failed jobs: #{e.message}"
end