Module: Aranha::Address::Scheduling

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_PRIORITY =
0

Instance Method Summary collapse

Instance Method Details

#allow_retry?Boolean

Returns:

  • (Boolean)


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

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

#check_schedulingObject



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

def check_scheduling
  ::ActiveRecord::Base.transaction do
    return unless schedule? # rubocop:disable Rails/TransactionExitStatement

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

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

Returns:

  • (Boolean)


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

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

#init_schedulingObject



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

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

#priorityObject



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

def priority
  processor_configuration.if_present(DEFAULT_PRIORITY, &:priority)
end

#schedule?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/aranha/address/scheduling.rb', line 47

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