Class: GoodJob::JobsFilter

Inherits:
BaseFilter show all
Defined in:
app/filters/good_job/jobs_filter.rb

Constant Summary

Constants inherited from BaseFilter

BaseFilter::DEFAULT_LIMIT, BaseFilter::EMPTY

Instance Attribute Summary

Attributes inherited from BaseFilter

#base_query, #params

Instance Method Summary collapse

Methods inherited from BaseFilter

#initialize, #job_classes, #last, #queues, #records, #to_params

Constructor Details

This class inherits a constructor from GoodJob::BaseFilter

Instance Method Details

#filtered_countObject



52
53
54
# File 'app/filters/good_job/jobs_filter.rb', line 52

def filtered_count
  @_filtered_count ||= filtered_query.unscope(:select).count
end

#filtered_query(filter_params = params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/filters/good_job/jobs_filter.rb', line 23

def filtered_query(filter_params = params)
  query = base_query

  query = query.job_class(filter_params[:job_class]) if filter_params[:job_class].present?
  query = query.where(queue_name: filter_params[:queue_name]) if filter_params[:queue_name].present?
  query = query.search_text(filter_params[:query]) if filter_params[:query].present?
  query = query.where(cron_key: filter_params[:cron_key]) if filter_params[:cron_key].present?
  query = query.where(finished_at: finished_since(filter_params[:finished_since])..) if filter_params[:finished_since].present?

  if filter_params[:state]
    case filter_params[:state]
    when 'discarded'
      query = query.discarded
    when 'succeeded'
      query = query.succeeded
    when 'retried'
      query = query.retried
    when 'scheduled'
      query = query.scheduled
    when 'running'
      query = query.running
    when 'queued'
      query = query.queued
    end
  end

  query
end

#state_namesObject



5
6
7
# File 'app/filters/good_job/jobs_filter.rb', line 5

def state_names
  %w[scheduled retried queued running succeeded discarded]
end

#statesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/filters/good_job/jobs_filter.rb', line 9

def states
  @_states ||= begin
    query = filtered_query(params.except(:state))
    {
      'scheduled' =>  query.scheduled.count,
      'retried' => query.retried.count,
      'queued' => query.queued.count,
      'running' => query.running.count,
      'succeeded' => query.succeeded.count,
      'discarded' => query.discarded.count,
    }
  end
end