Class: Resque::Plugins::JobHistory::JobSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/plugins/job_history/job_search.rb

Overview

This class searches through jobs looking for one which matches the passed in criteria.

Constant Summary collapse

ALL_ATTRIBUTES =
%i[search_type
job_class_name
search_for
regex_search
case_insensitive
last_class_name
last_job_id
last_job_group].freeze
SEARCH_TYPES =
%w[search_all search_job search_linear_history].freeze
DEFAULT_SEARCH_TIMEOUT =
10.seconds

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ JobSearch

Returns a new instance of JobSearch.

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
# File 'lib/resque/plugins/job_history/job_search.rb', line 25

def initialize(params)
  params = params.with_indifferent_access
  ALL_ATTRIBUTES.each do |attribute|
    instance_variable_set("@#{attribute}", params[attribute]) if params.key?(attribute)
  end

  raise ArgumentError, "invalid search_type" unless SEARCH_TYPES.include?(search_type)
end

Instance Method Details

#class_resultsObject



68
69
70
# File 'lib/resque/plugins/job_history/job_search.rb', line 68

def class_results
  @class_results ||= []
end

#more_records?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/resque/plugins/job_history/job_search.rb', line 76

def more_records?
  last_class_name || last_job_id
end

#retry_search_settings(all_settings) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/resque/plugins/job_history/job_search.rb', line 34

def retry_search_settings(all_settings)
  settings = search_settings(all_settings)

  %i[last_class_name
     last_job_id
     last_job_group].each do |continue_setting|
    settings.delete(continue_setting)
  end

  settings
end

#run_resultsObject



72
73
74
# File 'lib/resque/plugins/job_history/job_search.rb', line 72

def run_results
  @run_results ||= []
end

#searchObject



62
63
64
65
66
# File 'lib/resque/plugins/job_history/job_search.rb', line 62

def search
  end_search?

  send search_type
end

#search_settings(all_settings) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/resque/plugins/job_history/job_search.rb', line 46

def search_settings(all_settings)
  settings = ALL_ATTRIBUTES.dup

  unless all_settings
    settings.delete :search_for
    settings.delete :regex_search
    settings.delete :case_insensitive
  end

  settings.each_with_object({}) do |setting, hash|
    hash[setting] = send(setting)

    hash.delete(setting) if hash[setting].blank?
  end
end

#search_timeoutObject



80
81
82
# File 'lib/resque/plugins/job_history/job_search.rb', line 80

def search_timeout
  DEFAULT_SEARCH_TIMEOUT
end