mirror of
https://github.com/ditkrg/outboxable.git
synced 2026-01-22 22:06:47 +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__)
|
source_root File.expand_path('../../templates', __dir__)
|
||||||
class_option :orm, type: :string, default: 'activerecord'
|
class_option :orm, type: :string, default: 'activerecord'
|
||||||
|
|
||||||
def initialize
|
def initialize(*args)
|
||||||
super
|
super(*args)
|
||||||
|
|
||||||
@orm = options[:orm] || 'activerecord'
|
@orm = options[:orm] || 'activerecord'
|
||||||
%w[activerecord mongoid].include?(@orm) || raise(ArgumentError, 'Invalid ORM. Only ActiveRecord and Mongoid are supported.')
|
%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)
|
exchange = channel.topic(@resource.exchange, durable: true)
|
||||||
|
|
||||||
# Publish the CloudEvent resource to the exchange
|
# 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
|
# Wait for confirmation
|
||||||
confirmed = channel.wait_for_confirms
|
confirmed = channel.wait_for_confirms
|
||||||
|
|||||||
@ -7,6 +7,7 @@ class CreateOutboxableOutboxes < ActiveRecord::Migration[7.0]
|
|||||||
|
|
||||||
t.string :exchange, null: false, default: ''
|
t.string :exchange, null: false, default: ''
|
||||||
t.string :routing_key, 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.integer :attempts, null: false, default: 0
|
||||||
t.datetime :last_attempted_at, null: true
|
t.datetime :last_attempted_at, null: true
|
||||||
@ -21,5 +22,7 @@ class CreateOutboxableOutboxes < ActiveRecord::Migration[7.0]
|
|||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index :outboxes, %i[status last_attempted_at], name: 'index_outboxes_on_outboxable_status_and_last_attempted_at'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -10,6 +10,7 @@ class Outbox
|
|||||||
|
|
||||||
field :exchange, type: String, default: ''
|
field :exchange, type: String, default: ''
|
||||||
field :routing_key, type: String, default: ''
|
field :routing_key, type: String, default: ''
|
||||||
|
field :content_type, type: String, default: 'application/json'
|
||||||
|
|
||||||
field :attempts, type: Integer, default: 0
|
field :attempts, type: Integer, default: 0
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user