outboxer 0.1.9 → 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/generators/outboxer/templates/bin/publisher.rb +3 -4
- data/lib/outboxer/publisher.rb +28 -11
- data/lib/outboxer/version.rb +1 -1
- data/lib/tasks/gem.rake +58 -0
- metadata +2 -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
@@ -2,11 +2,10 @@
|
|
2
2
|
|
3
3
|
require_relative "../config/environment"
|
4
4
|
|
5
|
-
Outboxer::Publisher.publish do |
|
6
|
-
logger = args.logger
|
7
|
-
message = args.message
|
8
|
-
|
5
|
+
Outboxer::Publisher.publish do |message:, logger:|
|
9
6
|
logger.info("[#{message.id}] publishing")
|
7
|
+
|
10
8
|
HardJob.perform_async({ "message_id" => message.id })
|
9
|
+
|
11
10
|
logger.info("[#{message.id}] published")
|
12
11
|
end
|
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
data/lib/tasks/gem.rake
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "rake/packagetask"
|
2
|
+
|
3
|
+
namespace :gem do
|
4
|
+
desc "Bump version number"
|
5
|
+
task :bump, [:type] do |_t, args|
|
6
|
+
args.with_defaults(type: "patch")
|
7
|
+
|
8
|
+
unless %w[major minor patch].include?(args[:type])
|
9
|
+
raise "Invalid version type - choose from major/minor/patch"
|
10
|
+
end
|
11
|
+
|
12
|
+
version_file = File.expand_path("../../lib/outboxer/version.rb", __dir__)
|
13
|
+
version = ""
|
14
|
+
File.open(version_file, "r") do |file|
|
15
|
+
version = file.read.match(/VERSION = "(.*)"/)[1]
|
16
|
+
end
|
17
|
+
|
18
|
+
version_parts = version.split(".").map(&:to_i)
|
19
|
+
case args[:type]
|
20
|
+
when "major"
|
21
|
+
version_parts[0] += 1
|
22
|
+
version_parts[1] = 0
|
23
|
+
version_parts[2] = 0
|
24
|
+
when "minor"
|
25
|
+
version_parts[1] += 1
|
26
|
+
version_parts[2] = 0
|
27
|
+
when "patch"
|
28
|
+
version_parts[2] += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
new_version = version_parts.join(".")
|
32
|
+
File.write(version_file, "module Outboxer\n VERSION = \"#{new_version}\".freeze\nend\n")
|
33
|
+
|
34
|
+
puts "Gem version bumped to #{new_version}"
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Build the gem"
|
38
|
+
task :build do
|
39
|
+
Outboxer.send(:remove_const, :VERSION) if Outboxer.const_defined?(:VERSION)
|
40
|
+
load "lib/outboxer/version.rb"
|
41
|
+
sh "gem build outboxer.gemspec"
|
42
|
+
|
43
|
+
puts "Gem built successfully."
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Push the gem to RubyGems"
|
47
|
+
task :push do
|
48
|
+
Outboxer.send(:remove_const, :VERSION) if Outboxer.const_defined?(:VERSION)
|
49
|
+
load "lib/outboxer/version.rb"
|
50
|
+
version = Outboxer::VERSION
|
51
|
+
sh "gem push outboxer-#{version}.gem"
|
52
|
+
|
53
|
+
puts "Gem pushed to RubyGems."
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "Bump, build and push the gem to RubyGems"
|
57
|
+
task release: %i[bump build push]
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: outboxer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Mikulasev
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/outboxer/publisher.rb
|
50
50
|
- lib/outboxer/railtie.rb
|
51
51
|
- lib/outboxer/version.rb
|
52
|
+
- lib/tasks/gem.rake
|
52
53
|
- outboxer.gemspec
|
53
54
|
- sig/outboxer.rbs
|
54
55
|
homepage: https://github.com/fast-programmer/outboxer
|