Module: Aranha::Address::Scheduling

Included in:
Aranha::Address
Defined in:
app/models/aranha/address/scheduling.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#allow_retry?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/aranha/address/scheduling.rb', line 38

def allow_retry?
  tries_count < ::Aranha::Processor::DEFAULT_MAX_TRIES
end

#check_schedulingObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/aranha/address/scheduling.rb', line 17

def check_scheduling
  ::ActiveRecord::Base.transaction do
    return unless schedule?

    job = ::Delayed::Job.enqueue(
      ::Aranha::Address::DelayedJob.new(id),
      queue: ::Aranha::Rails::Process::QUEUE
    )
    update!(delayed_job: job)
  end
end

#expired?(time = ::Time.zone.now) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/aranha/address/scheduling.rb', line 29

def expired?(time = ::Time.zone.now)
  time >= (created_at + timeout)
end

#init_schedulingObject



33
34
35
36
# File 'app/models/aranha/address/scheduling.rb', line 33

def init_scheduling
  update!(tries_count: 0, last_error: nil) unless processed?
  check_scheduling
end

#schedule?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/aranha/address/scheduling.rb', line 42

def schedule?
  processed_at.blank? && allow_retry? && delayed_job.blank? && enabled?
end