mirror of
https://github.com/ditkrg/outboxable.git
synced 2026-01-22 13:56:49 +00:00
Merge pull request #4 from muhammadnawzad/main
Indexes columns & adds `content_type` field
This commit is contained in:
commit
40cbf3342a
@ -5,8 +5,8 @@ module Outboxable
|
||||
source_root File.expand_path('../../templates', __dir__)
|
||||
class_option :orm, type: :string, default: 'activerecord'
|
||||
|
||||
def initialize
|
||||
super
|
||||
def initialize(*args)
|
||||
super(*args)
|
||||
|
||||
@orm = options[:orm] || 'activerecord'
|
||||
%w[activerecord mongoid].include?(@orm) || raise(ArgumentError, 'Invalid ORM. Only ActiveRecord and Mongoid are supported.')
|
||||
|
||||
@ -20,7 +20,12 @@ module Outboxable
|
||||
exchange = channel.topic(@resource.exchange, durable: true)
|
||||
|
||||
# Publish the CloudEvent resource to the exchange
|
||||
exchange.publish(to_envelope(resource: @resource), routing_key: @resource.routing_key, headers: @resource.try(:headers) || {})
|
||||
exchange.publish(
|
||||
to_envelope(resource: @resource),
|
||||
routing_key: @resource.routing_key,
|
||||
headers: @resource.try(:headers) || {},
|
||||
content_type: @resource.try(:content_type) || 'application/json'
|
||||
)
|
||||
|
||||
# Wait for confirmation
|
||||
confirmed = channel.wait_for_confirms
|
||||
|
||||
@ -7,6 +7,7 @@ class CreateOutboxableOutboxes < ActiveRecord::Migration[7.0]
|
||||
|
||||
t.string :exchange, null: false, default: ''
|
||||
t.string :routing_key, null: false, default: ''
|
||||
t.string :content_type, null: false, default: 'application/json'
|
||||
|
||||
t.integer :attempts, null: false, default: 0
|
||||
t.datetime :last_attempted_at, null: true
|
||||
@ -21,5 +22,7 @@ class CreateOutboxableOutboxes < ActiveRecord::Migration[7.0]
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :outboxes, %i[status last_attempted_at], name: 'index_outboxes_on_outboxable_status_and_last_attempted_at'
|
||||
end
|
||||
end
|
||||
|
||||
@ -10,6 +10,7 @@ class Outbox
|
||||
|
||||
field :exchange, type: String, default: ''
|
||||
field :routing_key, type: String, default: ''
|
||||
field :content_type, type: String, default: 'application/json'
|
||||
|
||||
field :attempts, type: Integer, default: 0
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user