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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15a242cddf0a5a417ce73dd0c1efcc3154838eed44fb175bb9fc2e558f189d12
4
- data.tar.gz: 56cdd168249595290e1046f34b6bc12d49402b8a7ea23979ff3638f2f9e8b3f9
3
+ metadata.gz: f881a119f2c2123b34c0a7153590c2eab9907b44045e64d51e16ce914e731bb6
4
+ data.tar.gz: d30a09f38f02fea3bce19895922d294e40dfb25555e1fcf4fd06b33560d1e2db
5
5
  SHA512:
6
- metadata.gz: 7fa08d4b955fd0d2aad7f73e1e43851ba1f65a23da80220e9b8345fad9651503bef7170523a65efa028b13243e57b8caaabcbaf9ba1d2c22d2ea98eb12e67137
7
- data.tar.gz: e32aabee5228d8ab6a25965a1e393258a15db09948ee7f451bf3001eb9b29dfe53009d485ce837c67e74bb32800fbfd2947bad11a53136b422739667ab389fcc
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 |args|
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 with 4 key benefits in mind:
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. speed of integration into existing Ruby on Rails applications (< 1 hour)
91
- 2. comprehensive documentation that is easy to understand
92
- 3. high reliability in production environments (100% code coverage)
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
@@ -1,5 +1,3 @@
1
- # require "bundler/gem_tasks"
2
- # require "bundler/setup"
3
1
  require "rspec/core/rake_task"
4
2
 
5
3
  RSpec::Core::RakeTask.new(:spec)
@@ -2,11 +2,10 @@
2
2
 
3
3
  require_relative "../config/environment"
4
4
 
5
- Outboxer::Publisher.publish do |args|
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
@@ -7,19 +7,36 @@ module Outboxer
7
7
  @publishing = false
8
8
  @logger = Logger.new($stdout)
9
9
 
10
- Args = Struct.new(:message, :logger)
11
-
12
- # This method initiates the publishing process. It dequeues the messages one by one
13
- # and yields to a block that should contain the publishing logic.
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
- # @param [Integer] poll
16
- # Sleep time in seconds between polling the queue when it's empty.
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
- # @param [Proc] backoff
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
- # @yieldparam [Args] args
22
- # An Args object containing the message to publish and a logger.
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 Args.new(outboxer_message.message, @logger)
54
+ yield message: outboxer_message.message, logger: @logger
38
55
  rescue StandardError => exception
39
56
  failed(
40
57
  outboxer_message: outboxer_message,
@@ -1,3 +1,3 @@
1
1
  module Outboxer
2
- VERSION = "0.1.9".freeze
2
+ VERSION = "0.1.11".freeze
3
3
  end
@@ -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.9
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