ruby_event_store-outbox 0.0.18 → 0.0.21

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: 14cc2d7efea5445a91aad847cf380e9a5b743c2aa649ee8ca1d07b0093b13c36
4
- data.tar.gz: 3a42ce8411f6c7fe36acb2007b13b392570859c52f0111bad22db9be09216720
3
+ metadata.gz: 5db68b30315551cd7f8e2800c825b12710fd836e20a273b9a8be269955628fa3
4
+ data.tar.gz: f48d917e788f17731a1338129e399e6fa9919c38683ffed9202ca59b99816540
5
5
  SHA512:
6
- metadata.gz: 8919dc60db4ba6f37822a6fd1eff751b06b8c748f310c521157e2e41630bbe8b20705e93edeb66d1891f93c2cd9717cc407513bc2194e4c7f979102c540c3618
7
- data.tar.gz: a78188907f82607f3f3cf164b554748af7603589c8a60ab25face59d5d5efd73c3ea14cfaf6b599bd1abe2b6162efa978565ebdcc24ec68102f5a03f172b8737
6
+ metadata.gz: b0df42b4e20532df318b443950b6741df4130424b988602d6f2a141ff485f101ce845c97471faeb0d9403dc48d0411637f8d41a56a7cfa01ba87c9b2f4a05f9d
7
+ data.tar.gz: c8acb6b872bc7362d5362ab8299ccb1a4d099b92bf7f2c5685494fb0c7e5c1783d7925eb2c1e9df2f26e30c2e24010a1d59737a3a06d82175775f5278d69ac49
@@ -164,24 +164,23 @@ module RubyEventStore
164
164
  when :deadlocked
165
165
  logger.warn "Obtaining lock for split_key '#{fetch_specification.split_key}' failed (deadlock)"
166
166
  metrics.write_operation_result("obtain", "deadlocked")
167
- return false
167
+ false
168
168
  when :lock_timeout
169
169
  logger.warn "Obtaining lock for split_key '#{fetch_specification.split_key}' failed (lock timeout)"
170
170
  metrics.write_operation_result("obtain", "lock_timeout")
171
- return false
171
+ false
172
172
  when :taken
173
173
  logger.debug "Obtaining lock for split_key '#{fetch_specification.split_key}' unsuccessful (taken)"
174
174
  metrics.write_operation_result("obtain", "taken")
175
- return false
175
+ false
176
176
  else
177
- return result
177
+ result
178
178
  end
179
179
  end
180
180
 
181
181
  def release_lock_for_process(fetch_specification)
182
182
  result = repository.release_lock_for_process(fetch_specification, consumer_uuid)
183
183
  case result
184
- when :ok
185
184
  when :deadlocked
186
185
  logger.warn "Releasing lock for split_key '#{fetch_specification.split_key}' failed (deadlock)"
187
186
  metrics.write_operation_result("release", "deadlocked")
@@ -191,8 +190,6 @@ module RubyEventStore
191
190
  when :not_taken_by_this_process
192
191
  logger.debug "Releasing lock for split_key '#{fetch_specification.split_key}' failed (not taken by this process)"
193
192
  metrics.write_operation_result("release", "not_taken_by_this_process")
194
- else
195
- raise "Unexpected result #{result}"
196
193
  end
197
194
  end
198
195
 
@@ -221,15 +218,12 @@ module RubyEventStore
221
218
  def cleanup(fetch_specification)
222
219
  result = cleanup_strategy.call(fetch_specification)
223
220
  case result
224
- when :ok
225
221
  when :deadlocked
226
222
  logger.warn "Cleanup for split_key '#{fetch_specification.split_key}' failed (deadlock)"
227
223
  metrics.write_operation_result("cleanup", "deadlocked")
228
224
  when :lock_timeout
229
225
  logger.warn "Cleanup for split_key '#{fetch_specification.split_key}' failed (lock timeout)"
230
226
  metrics.write_operation_result("cleanup", "lock_timeout")
231
- else
232
- raise "Unexpected result #{result}"
233
227
  end
234
228
  end
235
229
 
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sidekiq_producer"
4
+
5
+ module RubyEventStore
6
+ module Outbox
7
+ class LegacySidekiqScheduler
8
+ def initialize
9
+ @sidekiq_producer = SidekiqProducer.new
10
+ end
11
+
12
+ def call(klass, serialized_record)
13
+ sidekiq_producer.call(klass, [serialized_record])
14
+ end
15
+
16
+ def verify(subscriber)
17
+ Class === subscriber && subscriber.respond_to?(:through_outbox?) && subscriber.through_outbox?
18
+ end
19
+
20
+ private
21
+ attr_reader :sidekiq_producer
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'influxdb'
2
+
3
+ module RubyEventStore
4
+ module Outbox
5
+ module Metrics
6
+ class Test
7
+ def initialize
8
+ @operation_results = []
9
+ @queue_stats = []
10
+ end
11
+
12
+ def write_operation_result(operation, result)
13
+ @operation_results << { operation: operation, result: result }
14
+ end
15
+
16
+ def write_point_queue(enqueued: 0, failed: 0, remaining: 0, format: nil, split_key: nil)
17
+ @queue_stats << { enqueued: enqueued, failed: failed, remaining: remaining, format: format, split_key: split_key}
18
+ end
19
+
20
+ attr_reader :operation_results, :queue_stats
21
+ end
22
+ end
23
+ end
24
+ end
@@ -36,7 +36,7 @@ module RubyEventStore
36
36
  transaction do
37
37
  l = get_lock_record(fetch_specification)
38
38
 
39
- if l.recently_locked?
39
+ if l.recently_locked?(clock: clock)
40
40
  :taken
41
41
  else
42
42
  l.update!(
@@ -89,8 +89,8 @@ module RubyEventStore
89
89
  locked_by.eql?(process_uuid)
90
90
  end
91
91
 
92
- def recently_locked?
93
- locked_by && locked_at > RECENTLY_LOCKED_DURATION.ago
92
+ def recently_locked?(clock:)
93
+ locked_by && locked_at > RECENTLY_LOCKED_DURATION.ago(clock.now)
94
94
  end
95
95
 
96
96
  def fetch_specification
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'sidekiq'
4
+ require_relative 'sidekiq5_format'
4
5
  require_relative "repository"
5
6
 
6
7
  module RubyEventStore
@@ -10,7 +11,7 @@ module RubyEventStore
10
11
  sidekiq_client = Sidekiq::Client.new(Sidekiq.redis_pool)
11
12
  item = {
12
13
  'class' => klass,
13
- 'args' => args,
14
+ 'args' => args.map(&:to_h).map {|h| h.transform_keys(&:to_s)},
14
15
  }
15
16
  normalized_item = sidekiq_client.__send__(:normalize_item, item)
16
17
  payload = sidekiq_client.__send__(:process_single, normalized_item.fetch('class'), normalized_item)
@@ -5,12 +5,13 @@ require_relative "sidekiq_producer"
5
5
  module RubyEventStore
6
6
  module Outbox
7
7
  class SidekiqScheduler
8
- def initialize
8
+ def initialize(serializer: YAML)
9
+ @serializer = serializer
9
10
  @sidekiq_producer = SidekiqProducer.new
10
11
  end
11
12
 
12
- def call(klass, serialized_record)
13
- sidekiq_producer.call(klass, [serialized_record.to_h])
13
+ def call(klass, record)
14
+ sidekiq_producer.call(klass, [record.serialize(serializer)])
14
15
  end
15
16
 
16
17
  def verify(subscriber)
@@ -18,7 +19,7 @@ module RubyEventStore
18
19
  end
19
20
 
20
21
  private
21
- attr_reader :sidekiq_producer
22
+ attr_reader :serializer, :sidekiq_producer
22
23
  end
23
24
  end
24
25
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyEventStore
4
4
  module Outbox
5
- VERSION = "0.0.18"
5
+ VERSION = "0.0.21"
6
6
  end
7
7
  end
@@ -8,5 +8,5 @@ end
8
8
  require_relative 'outbox/fetch_specification'
9
9
  require_relative 'outbox/repository'
10
10
  require_relative 'outbox/sidekiq_scheduler'
11
- require_relative 'outbox/consumer'
11
+ require_relative 'outbox/legacy_sidekiq_scheduler'
12
12
  require_relative 'outbox/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store-outbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2022-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_event_store
@@ -55,14 +55,14 @@ files:
55
55
  - lib/ruby_event_store/outbox/cleanup_strategies/none.rb
56
56
  - lib/ruby_event_store/outbox/cli.rb
57
57
  - lib/ruby_event_store/outbox/consumer.rb
58
- - lib/ruby_event_store/outbox/consumer_process.rb
59
58
  - lib/ruby_event_store/outbox/fetch_specification.rb
59
+ - lib/ruby_event_store/outbox/legacy_sidekiq_scheduler.rb
60
60
  - lib/ruby_event_store/outbox/metrics.rb
61
61
  - lib/ruby_event_store/outbox/metrics/influx.rb
62
62
  - lib/ruby_event_store/outbox/metrics/null.rb
63
+ - lib/ruby_event_store/outbox/metrics/test.rb
63
64
  - lib/ruby_event_store/outbox/repository.rb
64
65
  - lib/ruby_event_store/outbox/sidekiq5_format.rb
65
- - lib/ruby_event_store/outbox/sidekiq_message_handler.rb
66
66
  - lib/ruby_event_store/outbox/sidekiq_processor.rb
67
67
  - lib/ruby_event_store/outbox/sidekiq_producer.rb
68
68
  - lib/ruby_event_store/outbox/sidekiq_scheduler.rb
@@ -74,6 +74,7 @@ metadata:
74
74
  homepage_uri: https://railseventstore.org
75
75
  source_code_uri: https://github.com/RailsEventStore/rails_event_store
76
76
  bug_tracker_uri: https://github.com/RailsEventStore/rails_event_store/issues
77
+ rubygems_mfa_required: 'true'
77
78
  post_install_message:
78
79
  rdoc_options: []
79
80
  require_paths:
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  requirements: []
92
- rubygems_version: 3.0.3
93
+ rubygems_version: 3.1.6
93
94
  signing_key:
94
95
  specification_version: 4
95
96
  summary: Active Record based outbox for Ruby Event Store
@@ -1,6 +0,0 @@
1
- module RubyEventStore
2
- module Outbox
3
- class ConsumerProcess
4
- end
5
- end
6
- end
@@ -1,19 +0,0 @@
1
- require "sidekiq"
2
-
3
- module RubyEventStore
4
- module Outbox
5
- class SidekiqMessageHandler
6
- def initialize
7
- @sidekiq = Sidekiq::Client.new(Sidekiq.redis_pool)
8
- end
9
-
10
- def init
11
- end
12
-
13
- def handle_one_record(now, record)
14
- hash_payload = JSON.parse(record.payload)
15
- @sidekiq.__send__(:raw_push, [hash_payload])
16
- end
17
- end
18
- end
19
- end