Merge branch 'ditkrg:main' into main

This commit is contained in:
Muhammad Nawzad 2023-12-06 13:34:18 +03:00 committed by GitHub
commit eb6de394bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 6 deletions

View File

@ -1,7 +1,7 @@
PATH
remote: .
specs:
outboxable (1.0.3)
outboxable (1.0.5)
bunny (>= 2.19.0)
connection_pool (~> 2.3.0)

View File

@ -14,7 +14,7 @@ module Outboxable
# Copy initializer into user app
def copy_initializer
copy_file('activerecod_initializer.rb', 'config/initializers/z_outboxable.rb') if @orm == 'activerecord'
copy_file('activerecord_initializer.rb', 'config/initializers/z_outboxable.rb') if @orm == 'activerecord'
copy_file('mongoid_initializer.rb', 'config/initializers/z_outboxable.rb') if @orm == 'mongoid'
end

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module Outboxable
VERSION = '1.0.3'
VERSION = '1.0.5'
end

View File

@ -4,7 +4,7 @@ class Outbox < ApplicationRecord
before_save :check_publishing
# Callbacks
before_create :set_last_attempted_at
after_save :publish, if: :allow_publish
after_commit :publish, if: :allow_publish?
# Enums
enum status: { pending: 0, processing: 1, published: 2, failed: 3 }
enum size: { single: 0, batch: 1 }
@ -20,9 +20,13 @@ class Outbox < ApplicationRecord
end
def publish
Outboxable::Worker.perform_async(id)
# Run this in own thread
threaded = Thread.new do
Outboxable::Worker.perform_inline(id)
update(status: :processing, last_attempted_at: 1.minute.from_now, allow_publish: false)
end
threaded.join
end
def check_publishing
self.allow_publish = false if published?