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)


45
46
47
# File 'app/models/aranha/address/scheduling.rb', line 45

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

#check_schedulingObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/aranha/address/scheduling.rb', line 23

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)


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

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

#init_schedulingObject



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

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

#priorityObject



49
50
51
# File 'app/models/aranha/address/scheduling.rb', line 49

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

#schedule?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/aranha/address/scheduling.rb', line 53

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