Sha256: a659506d141b111ef03b0fc1858d6dc0783cd127b5ecf210bc934e170bb136f6

Contents?: true

Size: 760 Bytes

Versions: 3

Compression:

Stored size: 760 Bytes

Contents

class Inbox < ApplicationRecord
  attribute :allow_processing, :boolean, default: true

  # Callbacks
  after_commit :process, if: :allow_processing?

  # Scopes and Enums
  enum status: { pending: 0, processed: 1, failed: 2 }

  def increment_attempt
    self.attempts = attempts + 1
    self.last_attempted_at = Time.zone.now
  end

  def process
    processor_class_name.constantize.perform_async(id)
  end

  def check_threshold_reach
    return if attempts < ENV.fetch('INBOXABLE__MAX_ATTEMPTS', 3)&.to_i

    self.retry_at = Time.zone.now + ENV.fetch('INBOXABLE__RETRY_DELAY_IN_SECONDS', 5)&.to_i&.seconds
    self.status = :failed
    self.allow_processing = false
  end

  def check_publishing
    self.allow_processing = false if processed?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inboxable-0.1.2 lib/templates/activerecrod_inbox.rb
inboxable-0.1.1 lib/templates/activerecrod_inbox.rb
inboxable-0.1.0 lib/templates/activerecrod_inbox.rb