Merge pull request #4 from muhammadnawzad/main

Indexes columns & adds `content_type` field
This commit is contained in:
Brusk Awat 2024-05-28 14:22:41 +03:00 committed by GitHub
commit 40cbf3342a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 3 deletions

View File

@ -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.')

View File

@ -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

View File

@ -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

View File

@ -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