ruby_event_store-outbox 0.0.5 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_event_store/outbox/consumer.rb +24 -9
- data/lib/ruby_event_store/outbox/metrics.rb +2 -3
- data/lib/ruby_event_store/outbox/metrics/influx.rb +12 -4
- data/lib/ruby_event_store/outbox/metrics/null.rb +1 -1
- data/lib/ruby_event_store/outbox/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7e02fae40b268652d0187bfff203ea94993204069992b05d71808a3a820b28b
|
4
|
+
data.tar.gz: c78fdc01af8ca386f23babbcc409535e4c983238af4a13e3541d32f8b30b7f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 |
|
90
|
+
records.group_by(&:split_key).each do |split_key, records2|
|
87
91
|
begin
|
88
|
-
|
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
|
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 #{
|
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
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
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]
|
25
|
-
|
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
|
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.
|
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-
|
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
|