ruby_event_store-outbox 0.0.5 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a53d0609414ba7c53da1a8602042de223631437392a9a29b0e3dbb3d2015a61
4
- data.tar.gz: fa4dde249eecb5701f311d91a772fc12394b5412c6af18649d5ba604b11c9567
3
+ metadata.gz: d7e02fae40b268652d0187bfff203ea94993204069992b05d71808a3a820b28b
4
+ data.tar.gz: c78fdc01af8ca386f23babbcc409535e4c983238af4a13e3541d32f8b30b7f96
5
5
  SHA512:
6
- metadata.gz: f8d236f0e1cb2236f3740e7f92ea19662df5af2350e729266c50635208e3d714ccef6dfdd1f9080ac9237467a88be351e07f656cd5ae2361223f4eb6c96fb3cc
7
- data.tar.gz: eb6718caa012a1d6f5ed52374108c0a74f2f7faf73ddb8208d17c2f0bdb636712ee30249865b8eb39d410c1f273721e0495fa53d2b3f32d06a8f2be98eb4459f
6
+ metadata.gz: cca7886a64c64912770e4415ec65523309c6af0ef5edbc0c3d5a55fd2e7937be36517104d0539a1436e006af5623f82d0f7be09e79f2b78604fd257c85d8c0ed
7
+ data.tar.gz: d8435157be3745483024b2ddbc867502a0a340a10846485b35ac204eba845b5e05da924f24771b9b8e697b911c9c3eb605c5d7129c4fe8c9e0d66ca04138e6eb
@@ -46,6 +46,10 @@ module RubyEventStore
46
46
  @metrics = metrics
47
47
  @batch_size = configuration.batch_size
48
48
  ActiveRecord::Base.establish_connection(configuration.database_url) unless ActiveRecord::Base.connected?
49
+ if ActiveRecord::Base.connection.adapter_name == "Mysql2"
50
+ ActiveRecord::Base.connection.execute("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;")
51
+ ActiveRecord::Base.connection.execute("SET SESSION innodb_lock_wait_timeout = 1;")
52
+ end
49
53
 
50
54
  raise "Unknown format" if configuration.message_format != SIDEKIQ5_FORMAT
51
55
  @message_format = SIDEKIQ5_FORMAT
@@ -83,11 +87,12 @@ module RubyEventStore
83
87
 
84
88
  now = @clock.now.utc
85
89
  failed_record_ids = []
86
- records.each do |record|
90
+ records.group_by(&:split_key).each do |split_key, records2|
87
91
  begin
88
- handle_one_record(now, record)
92
+ failed = handle_group_of_records(now, split_key, records2)
93
+ failed_record_ids.concat(failed.map(&:id))
89
94
  rescue => e
90
- failed_record_ids << record.id
95
+ failed_record_ids.concat(records2.map(&:id))
91
96
  e.full_message.split($/).each {|line| logger.error(line) }
92
97
  end
93
98
  end
@@ -96,7 +101,7 @@ module RubyEventStore
96
101
  Record.where(id: updated_record_ids).update_all(enqueued_at: now)
97
102
  metrics.write_point_queue(status: "ok", enqueued: updated_record_ids.size, failed: failed_record_ids.size)
98
103
 
99
- logger.info "Sent #{records.size} messages from outbox table"
104
+ logger.info "Sent #{updated_record_ids.size} messages from outbox table"
100
105
  true
101
106
  end
102
107
  rescue ActiveRecord::Deadlocked
@@ -112,11 +117,21 @@ module RubyEventStore
112
117
  private
113
118
  attr_reader :split_keys, :logger, :message_format, :batch_size, :metrics
114
119
 
115
- def handle_one_record(now, record)
116
- hash_payload = JSON.parse(record.payload)
117
- @redis.lpush("queue:#{hash_payload.fetch("queue")}", JSON.generate(JSON.parse(record.payload).merge({
118
- "enqueued_at" => now.to_f,
119
- })))
120
+ def handle_group_of_records(now, split_key, records)
121
+ failed = []
122
+ elements = []
123
+ records.each do |record|
124
+ begin
125
+ elements << JSON.generate(JSON.parse(record.payload).merge({
126
+ "enqueued_at" => now.to_f,
127
+ }))
128
+ rescue => e
129
+ failed << record
130
+ e.full_message.split($/).each {|line| logger.error(line) }
131
+ end
132
+ end
133
+ @redis.lpush("queue:#{split_key}", elements)
134
+ failed
120
135
  end
121
136
 
122
137
  def prepare_traps
@@ -1,13 +1,12 @@
1
- require "ruby_event_store/outbox/metrics/null"
2
- require "ruby_event_store/outbox/metrics/influx"
3
-
4
1
  module RubyEventStore
5
2
  module Outbox
6
3
  module Metrics
7
4
  def self.from_url(metrics_url)
8
5
  if metrics_url.nil?
6
+ require "ruby_event_store/outbox/metrics/null"
9
7
  Null.new
10
8
  else
9
+ require "ruby_event_store/outbox/metrics/influx"
11
10
  Influx.new(metrics_url)
12
11
  end
13
12
  end
@@ -5,7 +5,16 @@ module RubyEventStore
5
5
  module Metrics
6
6
  class Influx
7
7
  def initialize(url)
8
- @influxdb_client = InfluxDB::Client.new(url: url, async: true, time_precision: 'ns')
8
+ uri = URI.parse(url)
9
+ params = CGI.parse(uri.query || "")
10
+ options = {
11
+ url: url,
12
+ async: true,
13
+ time_precision: 'ns',
14
+ }
15
+ options[:username] = params.fetch("username").first if params.key?("username")
16
+ options[:password] = params.fetch("password").first if params.key?("password")
17
+ @influxdb_client = InfluxDB::Client.new(**options)
9
18
  end
10
19
 
11
20
  def write_point_queue(status:, enqueued: 0, failed: 0)
@@ -21,11 +30,10 @@ module RubyEventStore
21
30
  end
22
31
 
23
32
  def write_point(series, data)
24
- data[:timestamp] ||= Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond).to_i
25
- @influxdb_client.write_point(series, data)
33
+ data[:timestamp] = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
34
+ influxdb_client.write_point(series, data)
26
35
  end
27
36
 
28
- private
29
37
  attr_reader :influxdb_client
30
38
  end
31
39
  end
@@ -2,7 +2,7 @@ module RubyEventStore
2
2
  module Outbox
3
3
  module Metrics
4
4
  class Null
5
- def write_point_queue(status:, enqueued: 0, failed: 0)
5
+ def write_point_queue(**kwargs)
6
6
  end
7
7
  end
8
8
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyEventStore
4
4
  module Outbox
5
- VERSION = "0.0.5"
5
+ VERSION = "0.0.10"
6
6
  end
7
7
  end
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.5
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-24 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_event_store