cyclone_lariat 0.2.1 → 0.2.2

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: b29f194e1ee444b5621fee3ad9be7547ad612c34acf8cf451d5be0f20976cc4e
4
- data.tar.gz: efdedb4530a004672b9c671c02b899fddedaa1d45b9876d28bce672f86f88812
3
+ metadata.gz: faa3648b8b458ed7430a3c42e24c883e24b4cce473a298fb453ec64a0471c1fd
4
+ data.tar.gz: 4c02a08f6f20a8c1ef3c43b1c86f953005eff6a1d7acc35d55fdaa66a3e852a6
5
5
  SHA512:
6
- metadata.gz: 4c784a8c6ec54fef60a529a09d6a45f9dd32bab493e2acabdabed7e2039e743cb547e132a38522ee1b8473a1e2f21644b8d7a25d8bd1daca498e2bef5cd390ee
7
- data.tar.gz: 85628b6886b4a82b639aa0f271b199e9cd85db4cbb316d4621637ca062ad996892f8c171ad32367a64f213b1ebcdd5e495e6f7cdb00f518923e87ecfe41a2610
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.0] - 2021-06-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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cyclone_lariat (0.2.1)
4
+ cyclone_lariat (0.2.2)
5
5
  aws-sdk-sns
6
6
  luna_park (~> 0.11)
7
7
 
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
- ![Luna Park](docs/_imgs/lariat.jpg)
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, null: false
146
- Integer :version, null: false
147
- String :publisher, null: false
148
- column :data, :json, null: false
149
- String :error_message, null: true, default: nil
150
- column :error_details, :json, null: true, default: nil
151
- DateTime :sent_at, null: true, default: nil
152
- DateTime :received_at, null: false, default: Sequel::CURRENT_TIMESTAMP
153
- DateTime :processed_at, null: true, default: nil
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
+ ```
@@ -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.'
@@ -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, null: false
8
- Integer :version, null: false
9
- String :publisher, null: false
10
- column :data, :json, null: false
11
- String :error_message, null: true, default: nil
12
- column :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
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
@@ -9,7 +9,7 @@ module CycloneLariat
9
9
  message { |d| "Could not found topic: `#{d[:expected_topic]}`" }
10
10
  end
11
11
 
12
- class ProcessingEventLogic < LunaPark::Errors::Business
12
+ class ClientError < LunaPark::Errors::Business
13
13
  attr_writer :message, :details
14
14
 
15
15
  def ==(other)
@@ -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 :error
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 error_message=(txt)
42
- @error ||= Errors::ProcessingEventLogic.new
43
- @error.message = txt
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 error_details=(details)
47
- @error ||= Errors::ProcessingEventLogic.new
48
- @error.details = details
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
- error&.message == other.error&.message &&
57
- error&.details == other.error&.details &&
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
- error_message: event.error&.message,
20
- error_details: JSON.generate(event.error&.details),
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
- !dataset.where(uuid: uuid).update(processed_at: Sequel.function(:NOW)).zero?
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] = JSON.parse(raw[:data], symbolize_names: true)
37
- raw[:error_details] = JSON.parse(raw[:error_details], symbolize_names: true) if raw[:error_details]
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] = JSON.parse(raw[:data], symbolize_names: true)
44
- raw[:error_details] = JSON.parse(raw[:error_details], symbolize_names: true) if raw[:error_details]
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&.warning(e, event: event)
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CycloneLariat
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
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.1
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-02 00:00:00.000000000 Z
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.6
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: []
data/config/db.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- DB_CONF = {
4
- adapter: 'postgresql',
5
- host: 'localhost',
6
- username: 'ruby',
7
- password: 'ruby',
8
- database: 'cyclone-lariat-test'
9
- }.freeze