Class: Periodically::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/periodically/job.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, method, opts) ⇒ Job

Returns a new instance of Job.



7
8
9
10
11
12
# File 'lib/periodically/job.rb', line 7

def initialize(klass, method, opts)
  @klass = klass
  @method = method
  @job_key = "#{klass.name}/#{method.to_s}"
  @opts = opts
end

Instance Method Details

#execute_instance(instance) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/periodically/job.rb', line 23

def execute_instance(instance)
  return_value =
    begin
      instance.send(@method)
    rescue => e
      Periodically.logger.error("Job instance[#{instance}] execution raised an error: #{e}")

      new_error_count = increase_instance_error_count(instance)
      lock_instance(instance, DEFAULT_ERROR_DELAY.call(new_error_count))
      return
    end

  clear_instance_error_count(instance)
end

#poll_next_instanceObject



14
15
16
17
18
19
20
21
# File 'lib/periodically/job.rb', line 14

def poll_next_instance
  ActiveRecord::Base.uncached do
    where = @opts[:on].call()
    where.to_a.find do |obj|
      !instance_locked?(obj)
    end
  end
end