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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b7fa112786d6fc9a6352d8dec8d8a88ddaa3e352e42bd9bc49c20639a7f173b
4
- data.tar.gz: 3edfd6a9e839c3ba75731abc42aa6c3c5d73faa84b39f9c556f39af46ab61ee7
3
+ metadata.gz: '09cf4072016f1a5b13d16bbef92f26ac4efaaa1d953b0a4752440e4acfda203a'
4
+ data.tar.gz: 7dd61b6f0bb552fd13e6e9f607c34fce18c44095c5902edc09b4cbfec0009e30
5
5
  SHA512:
6
- metadata.gz: 6117656da5d2fee53f531986690d311ac68f7a1c70d48f8870de6c3ee36f1aad6767a3b2c0f39c07b40a85b599a88df643d7275d37ca982295f678a6ea84ae52
7
- data.tar.gz: 4397e26b12d9c854ed80ae051701be3860dd410270a127899beeb6181b7e95e1634bc890b727c9c256cc74d292e5cab8aa9fdef514792881ba6136d2db946f23
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.info("[#{message.id}] publishing")
54
+ logger = args.logger
55
+ message = args.message
55
56
 
56
- Worker.perform_async({ message_id: args.message.id })
57
-
58
- args.logger.info("[#{message.id}] published")
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'
@@ -7,8 +7,6 @@ Outboxer::Publisher.publish do |args|
7
7
  message = args.message
8
8
 
9
9
  logger.info("[#{message.id}] publishing")
10
-
11
10
  HardJob.perform_async({ "message_id" => message.id })
12
-
13
11
  logger.info("[#{message.id}] published")
14
12
  end
@@ -0,0 +1,9 @@
1
+ require "active_record"
2
+
3
+ module Outboxer
4
+ class Exception < ::ActiveRecord::Base
5
+ self.table_name = :outboxer_exceptions
6
+
7
+ belongs_to :message, class_name: "::Outboxer::Message"
8
+ end
9
+ end
@@ -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
@@ -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 = Models::Message
58
- .where(status: Models::Message::STATUS[:unpublished])
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: Models::Message::STATUS[:publishing])
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: Models::Message::STATUS[:failed])
84
+ outboxer_message.update!(status: Message::STATUS[:failed])
85
85
 
86
86
  outboxer_message.exceptions.create!(
87
87
  class_name: exception.class.name,
@@ -1,3 +1,3 @@
1
1
  module Outboxer
2
- VERSION = "0.1.3".freeze
2
+ VERSION = "0.1.5"
3
3
  end
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
- require_relative "outboxer/models/outboxable"
6
- require_relative "outboxer/models/message"
7
- require_relative "outboxer/models/exception"
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/main/CHANGELOG.md"
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.3
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/models/exception.rb
47
- - lib/outboxer/models/message.rb
48
- - lib/outboxer/models/outboxable.rb
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/main/CHANGELOG.md
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,11 +0,0 @@
1
- require "active_record"
2
-
3
- module Outboxer
4
- module Models
5
- class Exception < ::ActiveRecord::Base
6
- self.table_name = :outboxer_exceptions
7
-
8
- belongs_to :message, class_name: "::Outboxer::Models::Message"
9
- end
10
- end
11
- end
@@ -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