Class: Outbox

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/templates/mongoid_outbox.rb,
lib/templates/activerecrod_outbox.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allow_publishObject



57
58
59
60
61
# File 'lib/templates/mongoid_outbox.rb', line 57

def allow_publish
  return true if @allow_publish.nil?

  @allow_publish
end

Instance Method Details

#check_publishingObject



53
54
55
# File 'lib/templates/mongoid_outbox.rb', line 53

def check_publishing
  self.allow_publish = false if published?
end

#publishObject



44
45
46
47
# File 'lib/templates/mongoid_outbox.rb', line 44

def publish
  Outboxable::Worker.perform_async(idempotency_key)
  update(status: :processing, last_attempted_at: 1.minute.from_now, allow_publish: false)
end

#set_idempotency_keyObject



49
50
51
# File 'lib/templates/mongoid_outbox.rb', line 49

def set_idempotency_key
  self.idempotency_key = SecureRandom.uuid if idempotency_key.blank?
end

#set_last_attempted_atObject



40
41
42
# File 'lib/templates/mongoid_outbox.rb', line 40

def set_last_attempted_at
  self.last_attempted_at = 10.seconds.from_now
end