Class: GoodJob::BaseFilter
- Inherits:
-
Object
- Object
- GoodJob::BaseFilter
show all
- Defined in:
- app/filters/good_job/base_filter.rb
Constant Summary
collapse
- DEFAULT_LIMIT =
25
- EMPTY =
'[none]'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(params, base_query = nil) ⇒ BaseFilter
Returns a new instance of BaseFilter.
10
11
12
13
|
# File 'app/filters/good_job/base_filter.rb', line 10
def initialize(params, base_query = nil)
@params = params
@base_query = base_query || default_base_query
end
|
Instance Attribute Details
#base_query ⇒ Object
Returns the value of attribute base_query.
8
9
10
|
# File 'app/filters/good_job/base_filter.rb', line 8
def base_query
@base_query
end
|
#params ⇒ Object
Returns the value of attribute params.
8
9
10
|
# File 'app/filters/good_job/base_filter.rb', line 8
def params
@params
end
|
Instance Method Details
#filtered_count ⇒ Object
68
69
70
|
# File 'app/filters/good_job/base_filter.rb', line 68
def filtered_count
filtered_query.count
end
|
#filtered_query(filtered_params = params) ⇒ Object
64
65
66
|
# File 'app/filters/good_job/base_filter.rb', line 64
def filtered_query(filtered_params = params)
raise NotImplementedError
end
|
#job_classes ⇒ Object
37
38
39
40
41
42
|
# File 'app/filters/good_job/base_filter.rb', line 37
def job_classes
filtered_query(params.slice(:queue_name)).unscope(:select)
.group(GoodJob::Job.params_job_class).count
.sort_by { |name, _count| name.to_s }
.to_h
end
|
#last ⇒ Object
27
28
29
|
# File 'app/filters/good_job/base_filter.rb', line 27
def last
@_last ||= records.last
end
|
#next_page_params ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'app/filters/good_job/base_filter.rb', line 76
def next_page_params
order_column = ordered_by.first
{
after_at: records.last&.send(order_column),
after_id: records.last&.id,
}.merge(to_params)
end
|
#ordered_by ⇒ Object
72
73
74
|
# File 'app/filters/good_job/base_filter.rb', line 72
def ordered_by
%w[created_at desc]
end
|
#queues ⇒ Object
31
32
33
34
35
|
# File 'app/filters/good_job/base_filter.rb', line 31
def queues
base_query.group(:queue_name).count
.sort_by { |name, _count| name.to_s || EMPTY }
.to_h
end
|
#records ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/filters/good_job/base_filter.rb', line 15
def records
after_at = params[:after_at].present? ? Time.zone.parse(params[:after_at]) : nil
after_id = params[:after_id] if after_at
limit = params.fetch(:limit, DEFAULT_LIMIT)
query_for_records.display_all(
ordered_by: ordered_by,
after_at: after_at,
after_id: after_id
).limit(limit)
end
|
#state_names ⇒ Object
48
49
50
|
# File 'app/filters/good_job/base_filter.rb', line 48
def state_names
raise NotImplementedError
end
|
#states ⇒ Object
44
45
46
|
# File 'app/filters/good_job/base_filter.rb', line 44
def states
raise NotImplementedError
end
|
#to_params(override = {}) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/filters/good_job/base_filter.rb', line 52
def to_params(override = {})
{
job_class: params[:job_class],
limit: params[:limit],
queue_name: params[:queue_name],
query: params[:query],
state: params[:state],
cron_key: params[:cron_key],
finished_since: params[:finished_since],
}.merge(override).delete_if { |_, v| v.blank? }
end
|