outboxable 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +17 -5
- data/lib/generators/outboxable/install_generator.rb +1 -1
- data/lib/outboxable/configuration.rb +6 -6
- data/lib/outboxable/polling_publisher_worker.rb +7 -9
- data/lib/outboxable/version.rb +1 -1
- data/lib/outboxable/worker.rb +3 -3
- data/lib/outboxable.rb +3 -2
- data/lib/templates/activerecord_initializer.rb +1 -1
- data/lib/templates/mongoid_initializer.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9045d9f58437a085928ba810ad1c7158c721b868dae4db4849cf209694895a6f
|
4
|
+
data.tar.gz: 147f241967d1f70c7837216e96dd36e4cf83dafe3f1fec5300467b83678a3227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50aac6397bfa33c7cafecc5f93b97801d4731507c4ac7e929667351f0e5802dc06e4966a9ab4f5e975a0e63d1d80f5c614379ab0baa8a4a09681d570ecaa8499
|
7
|
+
data.tar.gz: dcad50b82ec4a91d4de33cf6106b1b38cb1c03f340dab9c650ade2fb1a7f55b2ee68f2d6c7bfb6c9f04146286b2b9e738169aa78e81936cd5b7cd9a8d918bbf1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Outboxable
|
2
2
|
|
3
|
-
The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It
|
3
|
+
The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It supports both ActiveRecord and Mongoid.
|
4
4
|
|
5
5
|
Please take into consideration that this Gem is **opinionated**, meaning it expects you to follow a certain pattern and specific setting. If you don't like it, you can always fork it and change it.
|
6
6
|
|
@@ -25,13 +25,19 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
25
25
|
$ gem install outboxable
|
26
26
|
```
|
27
27
|
|
28
|
-
|
28
|
+
For use with ActiveRecord, run:
|
29
29
|
|
30
30
|
```shell
|
31
|
-
$ rails g outboxable:install
|
31
|
+
$ rails g outboxable:install --orm activerecord
|
32
32
|
```
|
33
33
|
|
34
|
-
|
34
|
+
For use with Mongoid, run:
|
35
|
+
|
36
|
+
```shell
|
37
|
+
$ rails g outboxable:install --orm mongoid
|
38
|
+
```
|
39
|
+
|
40
|
+
The command above will add a migration file and the Outbox model. You will need then to run the migrations (ActiveRecord only):
|
35
41
|
|
36
42
|
```shell
|
37
43
|
$ rails db:migrate
|
@@ -64,7 +70,7 @@ module Outboxable
|
|
64
70
|
end
|
65
71
|
|
66
72
|
Outboxable.configure do |config|
|
67
|
-
# Specify the ORM you are using.
|
73
|
+
# Specify the ORM you are using. Supported values are :activerecord and :mongoid
|
68
74
|
config.orm = :activerecord
|
69
75
|
|
70
76
|
# Specify the message broker you are using. For now, only RabbitMQ is supported.
|
@@ -208,6 +214,12 @@ Last but not least, run sidekiq so that the Outboxable Gem can publish the event
|
|
208
214
|
$ bundle exec sidekiq
|
209
215
|
```
|
210
216
|
|
217
|
+
|
218
|
+
|
219
|
+
### Mongoid
|
220
|
+
|
221
|
+
The Outboxable gem works smoothly with Mongoid. It is to be noted that when used with Mongoid, Outboxable does not use the `_id` as the idempotency key. It creates a field called ``idempotency_key`` which is a UUID generated at the time of the insertion of the document.
|
222
|
+
|
211
223
|
## Development
|
212
224
|
|
213
225
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -14,7 +14,7 @@ module Outboxable
|
|
14
14
|
|
15
15
|
# Copy initializer into user app
|
16
16
|
def copy_initializer
|
17
|
-
copy_file('
|
17
|
+
copy_file('activerecord_initializer.rb', 'config/initializers/z_outboxable.rb') if @orm == 'activerecord'
|
18
18
|
copy_file('mongoid_initializer.rb', 'config/initializers/z_outboxable.rb') if @orm == 'mongoid'
|
19
19
|
end
|
20
20
|
|
@@ -6,12 +6,6 @@ module Outboxable
|
|
6
6
|
def self.configure
|
7
7
|
self.configuration ||= Configuration.new
|
8
8
|
yield(configuration)
|
9
|
-
|
10
|
-
# In accordance to sidekiq-cron README: https://github.com/sidekiq-cron/sidekiq-cron#under-the-hood
|
11
|
-
Sidekiq::Options[:cron_poll_interval] = 5
|
12
|
-
|
13
|
-
# Create the cron job for the polling publisher
|
14
|
-
Sidekiq::Cron::Job.create(name: 'OutboxablePollingPublisher', cron: '*/5 * * * * *', class: 'Outboxable::PollingPublisherWorker', args: [{ orm: configuration.orm }])
|
15
9
|
end
|
16
10
|
|
17
11
|
class Configuration
|
@@ -32,6 +26,12 @@ module Outboxable
|
|
32
26
|
raise Error, 'Outboxable Gem only supports Rails but you application does not seem to be a Rails app' unless Object.const_defined?('Rails')
|
33
27
|
raise Error, 'Outboxable Gem only support Rails version 7 and newer' if Rails::VERSION::MAJOR < 7
|
34
28
|
raise Error, 'Outboxable Gem uses the sidekiq-cron Gem. Make sure you add it to your project' unless Object.const_defined?('Sidekiq::Cron')
|
29
|
+
|
30
|
+
# In accordance to sidekiq-cron README: https://github.com/sidekiq-cron/sidekiq-cron#under-the-hood
|
31
|
+
Sidekiq::Options[:cron_poll_interval] = 5
|
32
|
+
|
33
|
+
# Create the cron job for the polling publisher
|
34
|
+
Sidekiq::Cron::Job.create(name: 'OutboxablePollingPublisher', cron: '*/5 * * * * *', class: 'Outboxable::PollingPublisherWorker')
|
35
35
|
end
|
36
36
|
|
37
37
|
def message_broker=(message_broker)
|
@@ -1,27 +1,25 @@
|
|
1
1
|
module Outboxable
|
2
2
|
class PollingPublisherWorker
|
3
3
|
include Sidekiq::Job
|
4
|
-
sidekiq_options queue: 'critical'
|
5
4
|
|
6
|
-
def perform
|
7
|
-
orm
|
8
|
-
orm == 'mongoid' ? perform_mongoid(orm) : perform_activerecord(orm)
|
5
|
+
def perform
|
6
|
+
Outboxable.configuration.orm == :mongoid ? perform_mongoid : perform_activerecord
|
9
7
|
end
|
10
8
|
|
11
|
-
def perform_activerecord
|
9
|
+
def perform_activerecord
|
12
10
|
Outbox.pending.where(last_attempted_at: [..Time.zone.now, nil]).find_in_batches(batch_size: 100).each do |batch|
|
13
11
|
batch.each do |outbox|
|
14
12
|
# This is to prevent a job from being retried too many times. Worst-case scenario is 1 minute delay in jobs.
|
15
|
-
Outboxable::Worker.perform_async(outbox.id
|
13
|
+
::Outboxable::Worker.perform_async(outbox.id)
|
16
14
|
outbox.update(last_attempted_at: 1.minute.from_now, status: :processing, allow_publish: false)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
|
-
def perform_mongoid
|
22
|
-
Outbox.pending.
|
19
|
+
def perform_mongoid
|
20
|
+
Outbox.pending.any_of({ last_attempted_at: ..Time.zone.now }, { last_attempted_at: nil }).each do |outbox|
|
23
21
|
# This is to prevent a job from being retried too many times. Worst-case scenario is 1 minute delay in jobs.
|
24
|
-
Outboxable::Worker.perform_async(outbox.idempotency_key
|
22
|
+
::Outboxable::Worker.perform_async(outbox.idempotency_key)
|
25
23
|
outbox.update(last_attempted_at: 1.minute.from_now, status: :processing, allow_publish: false)
|
26
24
|
end
|
27
25
|
end
|
data/lib/outboxable/version.rb
CHANGED
data/lib/outboxable/worker.rb
CHANGED
@@ -4,9 +4,9 @@ module Outboxable
|
|
4
4
|
class Worker
|
5
5
|
include ::Sidekiq::Job
|
6
6
|
|
7
|
-
def perform(outbox_id
|
8
|
-
Outboxable::PublishingManager.publish(resource: Outbox.find(outbox_id)) if orm ==
|
9
|
-
Outboxable::PublishingManager.publish(resource: Outbox.find_by!(idempotency_key: outbox_id)) if orm ==
|
7
|
+
def perform(outbox_id)
|
8
|
+
Outboxable::PublishingManager.publish(resource: Outbox.find(outbox_id)) if Outboxable.configuration.orm == :activerecord
|
9
|
+
Outboxable::PublishingManager.publish(resource: Outbox.find_by!(idempotency_key: outbox_id)) if Outboxable.configuration.orm == :mongoid
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/outboxable.rb
CHANGED
@@ -3,14 +3,15 @@
|
|
3
3
|
require_relative 'outboxable/version'
|
4
4
|
|
5
5
|
require 'outboxable/worker'
|
6
|
-
require 'outboxable/publishing_manager'
|
7
|
-
require 'outboxable/polling_publisher_worker'
|
8
6
|
require 'outboxable/connection'
|
9
7
|
require 'outboxable/configuration'
|
10
8
|
require 'outboxable/rabbitmq/publisher'
|
11
9
|
|
12
10
|
require 'active_support/concern'
|
13
11
|
|
12
|
+
require 'outboxable/publishing_manager'
|
13
|
+
require 'outboxable/polling_publisher_worker'
|
14
|
+
|
14
15
|
module Outboxable
|
15
16
|
class Error < StandardError; end
|
16
17
|
|
@@ -23,7 +23,7 @@ Outboxable.configure do |config|
|
|
23
23
|
# Specify the ORM you are using. For now, only ActiveRecord is supported.
|
24
24
|
config.orm = :activerecord
|
25
25
|
|
26
|
-
# Specify the
|
26
|
+
# Specify the ORM you are using. Supported values are :activerecord and :mongoid
|
27
27
|
config.message_broker = :rabbitmq
|
28
28
|
|
29
29
|
# RabbitMQ configurations
|
@@ -23,7 +23,7 @@ Outboxable.configure do |config|
|
|
23
23
|
# Specify the ORM you are using. For now, only ActiveRecord is supported.
|
24
24
|
config.orm = :mongoid
|
25
25
|
|
26
|
-
# Specify the
|
26
|
+
# Specify the ORM you are using. Supported values are :activerecord and :mongoid
|
27
27
|
config.message_broker = :rabbitmq
|
28
28
|
|
29
29
|
# RabbitMQ configurations
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: outboxable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brusk Awat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|