Module: SimpleJob::JobDefinition::ClassMethods

Defined in:
lib/simple_job/job_definition.rb

Instance Method Summary collapse

Instance Method Details

#definitionObject



183
184
185
# File 'lib/simple_job/job_definition.rb', line 183

def definition
  @definition
end

#job_queue(queue_type = nil) ⇒ Object



216
217
218
219
# File 'lib/simple_job/job_definition.rb', line 216

def job_queue(queue_type = nil)
  @job_queue = JobQueue[queue_type] if queue_type
  @job_queue
end

#loggerObject



247
248
249
# File 'lib/simple_job/job_definition.rb', line 247

def logger
  @logger ||= JobLoggerWrapper.new(SimpleJob::JobQueue.config[:logger], definition[:type])
end

#max_attempt_count(attempts = nil) ⇒ Object



211
212
213
214
# File 'lib/simple_job/job_definition.rb', line 211

def max_attempt_count(attempts = nil)
  @max_attempt_count = attempts if attempts 
  @max_attempt_count
end

#register_simple_job(options = {}) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/simple_job/job_definition.rb', line 187

def register_simple_job(options = {})
  default_type = self.name.split('::').last.underscore.to_sym

  replace_existing = options.delete(:replace_existing)
  replace_existing = true if replace_existing.nil?

  new_definition = {
    :class => self,
    :type => default_type,
    :versions => [ '1' ],
  }.merge(options)

  new_definition[:type] = new_definition[:type].to_sym
  new_definition[:versions] = Array(new_definition[:versions])
  new_definition[:versions].collect! { |value| value.to_s }

  if replace_existing
    ::SimpleJob::JobDefinition.job_definitions.delete(@definition)
    @definition = new_definition
  end

  ::SimpleJob::JobDefinition.job_definitions << new_definition
end

#simple_job_attribute(*attributes) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/simple_job/job_definition.rb', line 225

def simple_job_attribute(*attributes)
  attributes.each do |attribute|
    attribute = attribute.to_sym

    if RESERVED_ATTRIBUTES.include?(attribute)
      raise "attempted to declare reserved attribute: #{attribute}"
    end

    simple_job_attributes << attribute

    class_eval <<-__EOF__
      def #{attribute}
        read_simple_job_attribute(:#{attribute})
      end

      def #{attribute}=(value)
        write_simple_job_attribute(:#{attribute}, value)
      end
    __EOF__
  end
end

#simple_job_attributesObject



221
222
223
# File 'lib/simple_job/job_definition.rb', line 221

def simple_job_attributes
  @simple_job_attributes ||= []
end