cyclone_lariat 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +45 -0
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +32 -10
- data/cyclone_lariat.gemspec +1 -1
- data/db/migrate/02_add_events.rb +9 -9
- data/docs/_imgs/diagram.png +0 -0
- data/lib/cyclone_lariat/errors.rb +1 -1
- data/lib/cyclone_lariat/event.rb +13 -9
- data/lib/cyclone_lariat/events_repo.rb +23 -8
- data/lib/cyclone_lariat/middleware.rb +3 -2
- data/lib/cyclone_lariat/version.rb +1 -1
- metadata +9 -9
- data/config/db.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faa3648b8b458ed7430a3c42e24c883e24b4cce473a298fb453ec64a0471c1fd
|
4
|
+
data.tar.gz: 4c02a08f6f20a8c1ef3c43b1c86f953005eff6a1d7acc35d55fdaa66a3e852a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3c140159b9bfe436de388f6e471f30131bc37d12cc8e8ab37be43657a4c840959d2795ae533521aba73a7b4d518170294f55c46f8693ee026888c0fd971ffc6
|
7
|
+
data.tar.gz: ba1c7d426dc58f5bff1d3e7ee4768f7b5de09e76f244825c1a20338012e83c6eb656f5139a1852dcab23c6a241081b295c029e87565c2539077f2c26e3039877
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
permissions:
|
14
|
+
contents: read
|
15
|
+
packages: write
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- name: Set up Ruby 2.6
|
20
|
+
uses: actions/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: 2.6.x
|
23
|
+
|
24
|
+
- name: Publish to GPR
|
25
|
+
run: |
|
26
|
+
mkdir -p $HOME/.gem
|
27
|
+
touch $HOME/.gem/credentials
|
28
|
+
chmod 0600 $HOME/.gem/credentials
|
29
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
30
|
+
gem build *.gemspec
|
31
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
32
|
+
env:
|
33
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
34
|
+
OWNER: ${{ github.repository_owner }}
|
35
|
+
|
36
|
+
- name: Publish to RubyGems
|
37
|
+
run: |
|
38
|
+
mkdir -p $HOME/.gem
|
39
|
+
touch $HOME/.gem/credentials
|
40
|
+
chmod 0600 $HOME/.gem/credentials
|
41
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
42
|
+
gem build *.gemspec
|
43
|
+
gem push *.gem
|
44
|
+
env:
|
45
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [0.2.
|
7
|
+
## [0.2.2] - 2021-06-2
|
8
|
+
Changed
|
9
|
+
- Fix save to database
|
10
|
+
- Rename error to client error
|
11
|
+
|
12
|
+
## [0.2.1] - 2021-06-2
|
8
13
|
Changed
|
9
14
|
- Fix can load from database if error_details is nil
|
10
15
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This is gem work like middleware for [shoryuken](https://github.com/ruby-shoryuken/shoryuken). It save all events to database. And catch and produce all exceptions.
|
4
4
|
|
5
|
-
![
|
5
|
+
![Cyclone lariat](docs/_imgs/lariat.jpg)
|
6
6
|
|
7
7
|
|
8
8
|
```ruby
|
@@ -15,6 +15,10 @@ gem 'cyclone_lariat', require: false
|
|
15
15
|
gem 'cyclone_lariat'
|
16
16
|
```
|
17
17
|
|
18
|
+
## Logic
|
19
|
+
|
20
|
+
![diagram](docs/_imgs/diagram.png)
|
21
|
+
|
18
22
|
|
19
23
|
## Client
|
20
24
|
|
@@ -142,16 +146,34 @@ Sequel.migration do
|
|
142
146
|
change do
|
143
147
|
create_table :events do
|
144
148
|
column :uuid, :uuid, primary_key: true
|
145
|
-
String :type,
|
146
|
-
Integer :version,
|
147
|
-
String :publisher,
|
148
|
-
column :data, :json,
|
149
|
-
String :
|
150
|
-
column :
|
151
|
-
DateTime :sent_at,
|
152
|
-
DateTime :received_at,
|
153
|
-
DateTime :processed_at,
|
149
|
+
String :type, null: false
|
150
|
+
Integer :version, null: false
|
151
|
+
String :publisher, null: false
|
152
|
+
column :data, :json, null: false
|
153
|
+
String :client_error_message, null: true, default: nil
|
154
|
+
column :client_error_details, :json, null: true, default: nil
|
155
|
+
DateTime :sent_at, null: true, default: nil
|
156
|
+
DateTime :received_at, null: false, default: Sequel::CURRENT_TIMESTAMP
|
157
|
+
DateTime :processed_at, null: true, default: nil
|
154
158
|
end
|
155
159
|
end
|
156
160
|
end
|
157
161
|
```
|
162
|
+
|
163
|
+
### Rake tasks
|
164
|
+
|
165
|
+
For simplify write some Rake tasks you can use CycloneLariat::Repo.
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
# For retry all unprocessed
|
169
|
+
|
170
|
+
CycloneLariat.new(DB[:events]).each_unprocessed do |event|
|
171
|
+
# Your logic here
|
172
|
+
end
|
173
|
+
|
174
|
+
# For retry all events with client errors
|
175
|
+
|
176
|
+
CycloneLariat.new(DB[:events]).each_with_client_errors do |event|
|
177
|
+
# Your logic here
|
178
|
+
end
|
179
|
+
```
|
data/cyclone_lariat.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
19
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
20
|
if spec.respond_to?(:metadata)
|
21
|
-
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
# spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
22
|
else
|
23
23
|
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
24
|
'public gem pushes.'
|
data/db/migrate/02_add_events.rb
CHANGED
@@ -4,15 +4,15 @@ Sequel.migration do
|
|
4
4
|
change do
|
5
5
|
create_table :events do
|
6
6
|
column :uuid, :uuid, primary_key: true
|
7
|
-
String :type,
|
8
|
-
Integer :version,
|
9
|
-
String :publisher,
|
10
|
-
column :data, :json,
|
11
|
-
String :
|
12
|
-
column :
|
13
|
-
DateTime :sent_at,
|
14
|
-
DateTime :received_at,
|
15
|
-
DateTime :processed_at,
|
7
|
+
String :type, null: false
|
8
|
+
Integer :version, null: false
|
9
|
+
String :publisher, null: false
|
10
|
+
column :data, :json, null: false
|
11
|
+
String :client_error_message, null: true, default: nil
|
12
|
+
column :client_error_details, :json, null: true, default: nil
|
13
|
+
DateTime :sent_at, null: true, default: nil
|
14
|
+
DateTime :received_at, null: false, default: Sequel::CURRENT_TIMESTAMP
|
15
|
+
DateTime :processed_at, null: true, default: nil
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
Binary file
|
data/lib/cyclone_lariat/event.rb
CHANGED
@@ -10,7 +10,7 @@ module CycloneLariat
|
|
10
10
|
attr :uuid, String, :new
|
11
11
|
attr :publisher, String, :new
|
12
12
|
attr :type, String, :new
|
13
|
-
attr :
|
13
|
+
attr :client_error
|
14
14
|
attr :version
|
15
15
|
attr :data
|
16
16
|
|
@@ -38,14 +38,18 @@ module CycloneLariat
|
|
38
38
|
@processed_at = wrap_time(value)
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
41
|
+
def client_error_message=(txt)
|
42
|
+
return unless txt
|
43
|
+
|
44
|
+
@client_error ||= Errors::ClientError.new
|
45
|
+
@client_error.message = txt
|
44
46
|
end
|
45
47
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
48
|
+
def client_error_details=(details)
|
49
|
+
return unless details
|
50
|
+
|
51
|
+
@client_error ||= Errors::ClientError.new
|
52
|
+
@client_error.details = details
|
49
53
|
end
|
50
54
|
|
51
55
|
def ==(other)
|
@@ -53,8 +57,8 @@ module CycloneLariat
|
|
53
57
|
uuid == other.uuid &&
|
54
58
|
publisher == other.publisher &&
|
55
59
|
type == other.type &&
|
56
|
-
|
57
|
-
|
60
|
+
client_error&.message == other.client_error&.message &&
|
61
|
+
client_error&.details == other.client_error&.details &&
|
58
62
|
version == other.version &&
|
59
63
|
sent_at.to_i == other.sent_at.to_i &&
|
60
64
|
received_at.to_i == other.received_at.to_i
|
@@ -16,8 +16,8 @@ module CycloneLariat
|
|
16
16
|
type: event.type,
|
17
17
|
publisher: event.publisher,
|
18
18
|
data: JSON.generate(event.data),
|
19
|
-
|
20
|
-
|
19
|
+
client_error_message: event.client_error&.message,
|
20
|
+
client_error_details: JSON.generate(event.client_error&.details),
|
21
21
|
version: event.version,
|
22
22
|
sent_at: event.sent_at
|
23
23
|
)
|
@@ -27,21 +27,36 @@ module CycloneLariat
|
|
27
27
|
dataset.where(uuid: uuid).limit(1).any?
|
28
28
|
end
|
29
29
|
|
30
|
-
def processed!(uuid:)
|
31
|
-
|
30
|
+
def processed!(uuid:, error: nil)
|
31
|
+
data = { processed_at: Sequel.function(:NOW) }
|
32
|
+
data.merge!(
|
33
|
+
client_error_message: error&.message,
|
34
|
+
client_error_details: JSON.generate(error&.details),
|
35
|
+
) if error
|
36
|
+
|
37
|
+
!dataset.where(uuid: uuid).update(data).zero?
|
32
38
|
end
|
33
39
|
|
34
40
|
def find(uuid:)
|
35
41
|
raw = dataset.where(uuid: uuid).first
|
36
|
-
raw[:data]
|
37
|
-
raw[:
|
42
|
+
raw[:data] = JSON.parse(raw[:data], symbolize_names: true)
|
43
|
+
raw[:client_error_details] = JSON.parse(raw[:client_error_details], symbolize_names: true) if raw[:client_error_details]
|
38
44
|
Event.wrap raw
|
39
45
|
end
|
40
46
|
|
41
47
|
def each_unprocessed
|
42
48
|
dataset.where(processed_at: nil).each do |raw|
|
43
|
-
raw[:data]
|
44
|
-
raw[:
|
49
|
+
raw[:data] = JSON.parse(raw[:data], symbolize_names: true)
|
50
|
+
raw[:client_error_details] = JSON.parse(raw[:client_error_details], symbolize_names: true) if raw[:client_error_details]
|
51
|
+
event = Event.wrap(raw)
|
52
|
+
yield(event)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def each_with_client_errors
|
57
|
+
dataset.where { (processed_at !~ nil) & (client_error_message !~ nil) }.each do |raw|
|
58
|
+
raw[:data] = JSON.parse(raw[:data], symbolize_names: true)
|
59
|
+
raw[:client_error_details] = JSON.parse(raw[:client_error_details], symbolize_names: true) if raw[:client_error_details]
|
45
60
|
event = Event.wrap(raw)
|
46
61
|
yield(event)
|
47
62
|
end
|
@@ -38,13 +38,14 @@ module CycloneLariat
|
|
38
38
|
|
39
39
|
events_repo.create(event)
|
40
40
|
yield
|
41
|
-
events_repo.processed! uuid: event.uuid
|
41
|
+
events_repo.processed! uuid: event.uuid, error: event.client_error
|
42
42
|
end
|
43
43
|
|
44
44
|
def catch_business_error(event)
|
45
45
|
yield
|
46
46
|
rescue LunaPark::Errors::Business => e
|
47
|
-
errors_notifier&.
|
47
|
+
errors_notifier&.error(e, event: event)
|
48
|
+
event.client_error = e
|
48
49
|
end
|
49
50
|
|
50
51
|
def catch_standard_error(queue, body)
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyclone_lariat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kudrin
|
8
8
|
- Philip Sorokin
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-06-
|
12
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk-sns
|
@@ -235,13 +235,14 @@ dependencies:
|
|
235
235
|
- - "~>"
|
236
236
|
- !ruby/object:Gem::Version
|
237
237
|
version: '0.9'
|
238
|
-
description:
|
238
|
+
description:
|
239
239
|
email:
|
240
240
|
- kudrin.alexander@gmail.com
|
241
241
|
executables: []
|
242
242
|
extensions: []
|
243
243
|
extra_rdoc_files: []
|
244
244
|
files:
|
245
|
+
- ".github/workflows/gem-push.yml"
|
245
246
|
- ".gitignore"
|
246
247
|
- ".rspec"
|
247
248
|
- ".rubocop.yml"
|
@@ -253,10 +254,10 @@ files:
|
|
253
254
|
- README.md
|
254
255
|
- Rakefile
|
255
256
|
- config/db.example.rb
|
256
|
-
- config/db.rb
|
257
257
|
- cyclone_lariat.gemspec
|
258
258
|
- db/migrate/01_add_uuid_extensions.rb
|
259
259
|
- db/migrate/02_add_events.rb
|
260
|
+
- docs/_imgs/diagram.png
|
260
261
|
- docs/_imgs/lariat.jpg
|
261
262
|
- lib/cyclone_lariat.rb
|
262
263
|
- lib/cyclone_lariat/client.rb
|
@@ -270,9 +271,8 @@ homepage: https://am-team.github.io/cyclone_lariat/#/
|
|
270
271
|
licenses:
|
271
272
|
- MIT
|
272
273
|
metadata:
|
273
|
-
allowed_push_host: https://rubygems.org
|
274
274
|
yard.run: yri
|
275
|
-
post_install_message:
|
275
|
+
post_install_message:
|
276
276
|
rdoc_options: []
|
277
277
|
require_paths:
|
278
278
|
- lib
|
@@ -287,8 +287,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
287
|
- !ruby/object:Gem::Version
|
288
288
|
version: '0'
|
289
289
|
requirements: []
|
290
|
-
rubygems_version: 3.0.
|
291
|
-
signing_key:
|
290
|
+
rubygems_version: 3.0.3.1
|
291
|
+
signing_key:
|
292
292
|
specification_version: 4
|
293
293
|
summary: Shoryuken middleware for LunaPark based application.
|
294
294
|
test_files: []
|