ruby_event_store-outbox 0.0.6 → 0.0.11
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: e6e7bf65a4d5106581d89918d0bb21bf6f19ee4e08a6f525d27665b41c07b3b0
|
4
|
+
data.tar.gz: eb1350270156bfd886bc11b94dfe858beda55692aa9c72832ca23fcadafe5fc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eda134f0e4a489546c9b05fd541d27c83f24bdac1e60da244398df09e3b913c650180b0c3472d5d6c0afd502870f025de01d0e94389c90cd491c7504e9693697
|
7
|
+
data.tar.gz: c73fcda82e6635636ae1eccbaeb3c52d4b2c438a7a55e075fccc254d18e118b5ea79266b48926074ec38bdf51b2b81cd787c6f7a61bf6facb5086ab1a5dd166d
|
@@ -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.11
|
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
|