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
64
65
66
|
# File 'app/filters/good_job/base_filter.rb', line 64
def filtered_count
filtered_query.count
end
|
#filtered_query(filtered_params = params) ⇒ Object
60
61
62
|
# File 'app/filters/good_job/base_filter.rb', line 60
def filtered_query(filtered_params = params)
raise NotImplementedError
end
|
#job_classes ⇒ Object
34
35
36
37
38
39
|
# File 'app/filters/good_job/base_filter.rb', line 34
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
24
25
26
|
# File 'app/filters/good_job/base_filter.rb', line 24
def last
@_last ||= records.last
end
|
#queues ⇒ Object
28
29
30
31
32
|
# File 'app/filters/good_job/base_filter.rb', line 28
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
|
# File 'app/filters/good_job/base_filter.rb', line 15
def records
after_scheduled_at = params[:after_scheduled_at].present? ? Time.zone.parse(params[:after_scheduled_at]) : nil
query_for_records.display_all(
after_scheduled_at: after_scheduled_at,
after_id: params[:after_id]
).limit(params.fetch(:limit, DEFAULT_LIMIT))
end
|
#state_names ⇒ Object
45
46
47
|
# File 'app/filters/good_job/base_filter.rb', line 45
def state_names
raise NotImplementedError
end
|
#states ⇒ Object
41
42
43
|
# File 'app/filters/good_job/base_filter.rb', line 41
def states
raise NotImplementedError
end
|
#to_params(override = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'app/filters/good_job/base_filter.rb', line 49
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],
}.merge(override).delete_if { |_, v| v.blank? }
end
|