Module: Sidekiq::Job::Options::ClassMethods
- Defined in:
- lib/sidekiq/job.rb
Constant Summary collapse
- ACCESSOR_MUTEX =
Mutex.new
Instance Method Summary collapse
-
#get_sidekiq_options ⇒ Object
:nodoc:.
- #sidekiq_class_attribute(*attrs) ⇒ Object
-
#sidekiq_options(opts = {}) ⇒ Object
Allows customization for this type of Job.
- #sidekiq_retries_exhausted(&block) ⇒ Object
- #sidekiq_retry_in(&block) ⇒ Object
Instance Method Details
#get_sidekiq_options ⇒ Object
:nodoc:
88 89 90 |
# File 'lib/sidekiq/job.rb', line 88 def # :nodoc: self. ||= Sidekiq. end |
#sidekiq_class_attribute(*attrs) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/sidekiq/job.rb', line 92 def sidekiq_class_attribute(*attrs) instance_reader = true instance_writer = true attrs.each do |name| synchronized_getter = "__synchronized_#{name}" singleton_class.instance_eval do undef_method(name) if method_defined?(name) || private_method_defined?(name) end define_singleton_method(synchronized_getter) { nil } singleton_class.class_eval do private(synchronized_getter) end define_singleton_method(name) { ACCESSOR_MUTEX.synchronize { send synchronized_getter } } ivar = "@#{name}" singleton_class.instance_eval do m = "#{name}=" undef_method(m) if method_defined?(m) || private_method_defined?(m) end define_singleton_method(:"#{name}=") do |val| singleton_class.class_eval do ACCESSOR_MUTEX.synchronize do undef_method(synchronized_getter) if method_defined?(synchronized_getter) || private_method_defined?(synchronized_getter) define_method(synchronized_getter) { val } end end if singleton_class? class_eval do undef_method(name) if method_defined?(name) || private_method_defined?(name) define_method(name) do if instance_variable_defined? ivar instance_variable_get ivar else singleton_class.send name end end end end val end if instance_reader undef_method(name) if method_defined?(name) || private_method_defined?(name) define_method(name) do if instance_variable_defined?(ivar) instance_variable_get ivar else self.class.public_send name end end end if instance_writer m = "#{name}=" undef_method(m) if method_defined?(m) || private_method_defined?(m) attr_writer name end end end |
#sidekiq_options(opts = {}) ⇒ Object
Allows customization for this type of Job. Legal options:
queue - name of queue to use for this job type, default *default*
retry - enable retries for this Job in case of error during execution,
*true* to use the default or *Integer* count
backtrace - whether to save any error backtrace in the retry payload to display in web UI,
can be true, false or an integer number of lines to save, default *false*
In practice, any option is allowed. This is the main mechanism to configure the options for a specific job.
71 72 73 74 75 76 77 78 |
# File 'lib/sidekiq/job.rb', line 71 def (opts = {}) # stringify 2 levels of keys opts = opts.to_h do |k, v| [k.to_s, (Hash === v) ? v.transform_keys(&:to_s) : v] end self. = .merge(opts) end |
#sidekiq_retries_exhausted(&block) ⇒ Object
84 85 86 |
# File 'lib/sidekiq/job.rb', line 84 def sidekiq_retries_exhausted(&block) self.sidekiq_retries_exhausted_block = block end |
#sidekiq_retry_in(&block) ⇒ Object
80 81 82 |
# File 'lib/sidekiq/job.rb', line 80 def sidekiq_retry_in(&block) self.sidekiq_retry_in_block = block end |