outboxer 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -8
- data/Rakefile +0 -2
- data/lib/outboxer/publisher.rb +28 -11
- data/lib/outboxer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f881a119f2c2123b34c0a7153590c2eab9907b44045e64d51e16ce914e731bb6
|
4
|
+
data.tar.gz: d30a09f38f02fea3bce19895922d294e40dfb25555e1fcf4fd06b33560d1e2db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df0a95d0f24b7ff85038711be1acd4aec4dc5760accb390fb40fdf07342d911b5b07373c4eacbc2e05e25a7a89137ef26c20e201b556c6e07973469806eddaff
|
7
|
+
data.tar.gz: 1d329faae4668703b51cd5becdce8215e4251e1217d9c8311795ab602d71e140511b79874908963a947c24939025bd2dbcd8af0497aa985d9478f7919d7602d7
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Outboxer
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/outboxer.svg)](https://badge.fury.io/rb/outboxer)
|
4
|
+
![Ruby](https://github.com/fast-programmer/outboxer/actions/workflows/master.yml/badge.svg)
|
5
|
+
|
3
6
|
## Background
|
4
7
|
|
5
8
|
Typically in event driven Ruby on Rails applications:
|
@@ -50,12 +53,11 @@ end
|
|
50
53
|
#### 2. Update the generated bin/publish block e.g.
|
51
54
|
|
52
55
|
```ruby
|
53
|
-
Outboxer::Publisher.publish do |
|
54
|
-
logger = args.logger
|
55
|
-
message = args.message
|
56
|
-
|
56
|
+
Outboxer::Publisher.publish do |message:, logger:|
|
57
57
|
logger.info("[#{message.id}] publishing")
|
58
|
+
|
58
59
|
HardJob.perform_async({ "message_id" => message.id })
|
60
|
+
|
59
61
|
logger.info("[#{message.id}] published")
|
60
62
|
end
|
61
63
|
```
|
@@ -85,11 +87,13 @@ To see all the parts working together in a single place, check out the [publishe
|
|
85
87
|
|
86
88
|
## Motivation
|
87
89
|
|
88
|
-
Outboxer was created
|
90
|
+
Outboxer was created to help high growth SAAS companies transition to event driven architecture quickly.
|
91
|
+
|
92
|
+
Specifically this means:
|
89
93
|
|
90
|
-
1.
|
91
|
-
2. comprehensive documentation
|
92
|
-
3. high reliability in production environments
|
94
|
+
1. fast integration into existing Ruby on Rails applications (< 1 hour)
|
95
|
+
2. comprehensive documentation
|
96
|
+
3. high reliability in production environments
|
93
97
|
4. forever free to use in commerical applications (MIT licence)
|
94
98
|
|
95
99
|
## Contributing
|
data/Rakefile
CHANGED
data/lib/outboxer/publisher.rb
CHANGED
@@ -7,19 +7,36 @@ module Outboxer
|
|
7
7
|
@publishing = false
|
8
8
|
@logger = Logger.new($stdout)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
# This method
|
13
|
-
#
|
10
|
+
# Publishes messages from the Outboxer queue.
|
11
|
+
#
|
12
|
+
# This method will continue to publish messages from the queue as long
|
13
|
+
# as @publishing is set to true. It uses an ActiveRecord connection to
|
14
|
+
# handle database interactions.
|
15
|
+
#
|
16
|
+
# @param poll [Integer] the interval (in seconds) at which the method
|
17
|
+
# should poll the database for new messages.
|
18
|
+
# @param backoff [Proc] a callable object that defines how to increase the
|
19
|
+
# backoff time when an error occurs. It should accept the current backoff
|
20
|
+
# time as a parameter and return the new backoff time.
|
21
|
+
#
|
22
|
+
# @yield [Hash] once a message is dequeued, the method yields a hash to
|
23
|
+
# the given block. The hash contains the :message (the dequeued message)
|
24
|
+
# and :logger (the logger object).
|
25
|
+
#
|
26
|
+
# @yieldparam message [Message] the dequeued message from the Outboxer queue.
|
27
|
+
# @yieldparam logger [Logger] the logger instance to log any information or errors.
|
14
28
|
#
|
15
|
-
# @
|
16
|
-
#
|
29
|
+
# @raise [StandardError] if an error occurs during the yield, it is rescued,
|
30
|
+
# logged, and then the failed method is invoked to handle the error. The
|
31
|
+
# method then moves on to the next message in the queue.
|
17
32
|
#
|
18
|
-
# @
|
19
|
-
# A Proc that takes the current backoff time and returns the new backoff time.
|
33
|
+
# @return [void] This method does not have a meaningful return value.
|
20
34
|
#
|
21
|
-
# @
|
22
|
-
#
|
35
|
+
# @example Basic usage
|
36
|
+
# Outboxer::Publisher.publish(poll: 1) do |hash|
|
37
|
+
# puts hash[:message]
|
38
|
+
# puts hash[:logger]
|
39
|
+
# end
|
23
40
|
def publish(poll: 1, backoff: ->(current_backoff) { [current_backoff * 2, 5 * 60].min })
|
24
41
|
@publishing = true
|
25
42
|
|
@@ -34,7 +51,7 @@ module Outboxer
|
|
34
51
|
end
|
35
52
|
|
36
53
|
begin
|
37
|
-
yield
|
54
|
+
yield message: outboxer_message.message, logger: @logger
|
38
55
|
rescue StandardError => exception
|
39
56
|
failed(
|
40
57
|
outboxer_message: outboxer_message,
|
data/lib/outboxer/version.rb
CHANGED