outboxer 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/Rakefile +5 -1
- data/generators/outboxer/templates/bin/publisher.rb +0 -2
- data/lib/outboxer/exception.rb +9 -0
- data/lib/outboxer/message.rb +19 -0
- data/lib/outboxer/outboxable.rb +21 -0
- data/lib/outboxer/publisher.rb +4 -4
- data/lib/outboxer/version.rb +1 -1
- data/lib/outboxer.rb +4 -6
- data/outboxer.gemspec +1 -1
- metadata +5 -5
- data/lib/outboxer/models/exception.rb +0 -11
- data/lib/outboxer/models/message.rb +0 -21
- data/lib/outboxer/models/outboxable.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09cf4072016f1a5b13d16bbef92f26ac4efaaa1d953b0a4752440e4acfda203a'
|
4
|
+
data.tar.gz: 7dd61b6f0bb552fd13e6e9f607c34fce18c44095c5902edc09b4cbfec0009e30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc1a3b0e3cf6c7b29ede1469148d78a567456726a87113f5355209fa3623b35ec8e401ad3dcd155888d057c1c45bb95893c613aee5f849448a9a6eca6b5de2a
|
7
|
+
data.tar.gz: 84f3e8873c693f8c0652561a848f0da423764de489902456c335d9f638882964052f08e7a63e2d65fd020a0338110df8b84cf789a9b1fe87936b0ee68ed2ee14
|
data/README.md
CHANGED
@@ -51,11 +51,12 @@ end
|
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
Outboxer::Publisher.publish do |args|
|
54
|
-
args.logger
|
54
|
+
logger = args.logger
|
55
|
+
message = args.message
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
logger.info("[#{message.id}] publishing")
|
58
|
+
HardJob.perform_async({ "message_id" => message.id })
|
59
|
+
logger.info("[#{message.id}] published")
|
59
60
|
end
|
60
61
|
```
|
61
62
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
# require "bundler/gem_tasks"
|
2
|
+
# require "bundler/setup"
|
2
3
|
require "rspec/core/rake_task"
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
7
|
+
require 'pry'
|
6
8
|
require "rubocop/rake_task"
|
7
9
|
|
8
10
|
RuboCop::RakeTask.new
|
9
11
|
|
10
12
|
task default: %i[spec rubocop]
|
13
|
+
|
14
|
+
load 'lib/tasks/gem.rake'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
module Outboxer
|
4
|
+
class Message < ::ActiveRecord::Base
|
5
|
+
self.table_name = :outboxer_messages
|
6
|
+
|
7
|
+
STATUS = {
|
8
|
+
unpublished: "unpublished",
|
9
|
+
publishing: "publishing",
|
10
|
+
failed: "failed"
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
belongs_to :message, polymorphic: true
|
14
|
+
|
15
|
+
has_many :exceptions, -> { order(created_at: :asc) },
|
16
|
+
class_name: "::Outboxer::Exception",
|
17
|
+
dependent: :destroy
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Outboxer
|
2
|
+
module Outboxable
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
|
6
|
+
base.class_eval do
|
7
|
+
has_one :message, class_name: "::Outboxer::Message", as: :outbox_message,
|
8
|
+
dependent: :destroy
|
9
|
+
|
10
|
+
after_create :create_outbox_message!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_outbox_message!
|
15
|
+
Message.create!(message: self, status: Message::STATUS[:unpublished])
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/outboxer/publisher.rb
CHANGED
@@ -54,14 +54,14 @@ module Outboxer
|
|
54
54
|
def dequeue(backoff:)
|
55
55
|
retry_on_error(backoff: backoff) do
|
56
56
|
ActiveRecord::Base.transaction do
|
57
|
-
message =
|
58
|
-
.where(status:
|
57
|
+
message = Message
|
58
|
+
.where(status: Message::STATUS[:unpublished])
|
59
59
|
.order(created_at: :asc)
|
60
60
|
.limit(1)
|
61
61
|
.lock("FOR UPDATE SKIP LOCKED")
|
62
62
|
.first
|
63
63
|
|
64
|
-
message&.update!(status:
|
64
|
+
message&.update!(status: Message::STATUS[:publishing])
|
65
65
|
|
66
66
|
message
|
67
67
|
end
|
@@ -81,7 +81,7 @@ module Outboxer
|
|
81
81
|
|
82
82
|
retry_on_error(backoff: backoff) do
|
83
83
|
ActiveRecord::Base.transaction do
|
84
|
-
outboxer_message.update!(status:
|
84
|
+
outboxer_message.update!(status: Message::STATUS[:failed])
|
85
85
|
|
86
86
|
outboxer_message.exceptions.create!(
|
87
87
|
class_name: exception.class.name,
|
data/lib/outboxer/version.rb
CHANGED
data/lib/outboxer.rb
CHANGED
@@ -2,14 +2,12 @@ require "active_support"
|
|
2
2
|
|
3
3
|
require_relative "outboxer/version"
|
4
4
|
require_relative "outboxer/railtie" if defined?(Rails)
|
5
|
-
|
6
|
-
require_relative "outboxer/
|
7
|
-
require_relative "outboxer/
|
5
|
+
|
6
|
+
require_relative "outboxer/outboxable"
|
7
|
+
require_relative "outboxer/message"
|
8
|
+
require_relative "outboxer/exception"
|
8
9
|
|
9
10
|
require_relative "outboxer/publisher"
|
10
11
|
|
11
12
|
module Outboxer
|
12
|
-
Outboxable = Models::Outboxable
|
13
|
-
Message = Models::Message
|
14
|
-
Exception = Models::Exception
|
15
13
|
end
|
data/outboxer.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
16
|
spec.metadata["source_code_uri"] = "https://github.com/fast-programmer/outboxer"
|
17
17
|
spec.metadata["documentation_uri"] = "https://rubydoc.info/github/fast-programmer/outboxer/master"
|
18
|
-
spec.metadata["changelog_uri"] = "https://github.com/fast-programmer/outboxer/blob/
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/fast-programmer/outboxer/blob/master/CHANGELOG.md"
|
19
19
|
spec.metadata["rubygems_mfa_required"] = "true"
|
20
20
|
|
21
21
|
spec.files = Dir.chdir(__dir__) do
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Mikulasev
|
@@ -43,9 +43,9 @@ files:
|
|
43
43
|
- generators/outboxer/templates/migrations/create_outboxer_exceptions.rb
|
44
44
|
- generators/outboxer/templates/migrations/create_outboxer_messages.rb
|
45
45
|
- lib/outboxer.rb
|
46
|
-
- lib/outboxer/
|
47
|
-
- lib/outboxer/
|
48
|
-
- lib/outboxer/
|
46
|
+
- lib/outboxer/exception.rb
|
47
|
+
- lib/outboxer/message.rb
|
48
|
+
- lib/outboxer/outboxable.rb
|
49
49
|
- lib/outboxer/publisher.rb
|
50
50
|
- lib/outboxer/railtie.rb
|
51
51
|
- lib/outboxer/version.rb
|
@@ -58,7 +58,7 @@ metadata:
|
|
58
58
|
homepage_uri: https://github.com/fast-programmer/outboxer
|
59
59
|
source_code_uri: https://github.com/fast-programmer/outboxer
|
60
60
|
documentation_uri: https://rubydoc.info/github/fast-programmer/outboxer/master
|
61
|
-
changelog_uri: https://github.com/fast-programmer/outboxer/blob/
|
61
|
+
changelog_uri: https://github.com/fast-programmer/outboxer/blob/master/CHANGELOG.md
|
62
62
|
rubygems_mfa_required: 'true'
|
63
63
|
post_install_message:
|
64
64
|
rdoc_options: []
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "active_record"
|
2
|
-
|
3
|
-
module Outboxer
|
4
|
-
module Models
|
5
|
-
class Message < ::ActiveRecord::Base
|
6
|
-
self.table_name = :outboxer_messages
|
7
|
-
|
8
|
-
STATUS = {
|
9
|
-
unpublished: "unpublished",
|
10
|
-
publishing: "publishing",
|
11
|
-
failed: "failed"
|
12
|
-
}.freeze
|
13
|
-
|
14
|
-
belongs_to :message, polymorphic: true
|
15
|
-
|
16
|
-
has_many :exceptions, -> { order(created_at: :asc) },
|
17
|
-
class_name: "::Outboxer::Models::Exception",
|
18
|
-
dependent: :destroy
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Outboxer
|
2
|
-
module Models
|
3
|
-
module Outboxable
|
4
|
-
def self.included(base)
|
5
|
-
base.extend ClassMethods
|
6
|
-
|
7
|
-
base.class_eval do
|
8
|
-
has_one :message, class_name: "Outboxer::Models::Message", as: :outbox_message,
|
9
|
-
dependent: :destroy
|
10
|
-
|
11
|
-
after_create :create_outbox_message!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_outbox_message!
|
16
|
-
Models::Message.create!(message: self, status: Models::Message::STATUS[:unpublished])
|
17
|
-
end
|
18
|
-
|
19
|
-
module ClassMethods
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|