monitorsys-tortoise 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1079cf5e3cd6de98df9188a924dc2a157273bfd3fa3d4e3953c9a5382d254b42
4
- data.tar.gz: 4a8306c05e25dc68d751281591177012e3f04881e8be0eefd61e05a3f8a80515
3
+ metadata.gz: a666f4cec12d119f6b259253d8c6c57431c13903262bd9eb079eb47d46024048
4
+ data.tar.gz: 8ca38c24e3445e8f0c066e181ec5079365915a9d82a48093c83d21159d129f17
5
5
  SHA512:
6
- metadata.gz: d50e02385844a4d3e4feee61bdebcbba8cba5b8ba728408ecd0a3006399b673f3c6160f67eb765e097c4de93f37f895bc920c704520d7372d0139c2fdc39d4c1
7
- data.tar.gz: 3e1d9ecd2fde55fa82332ebf8a8df1867e1f50005f5185cfaab8627d65ef9c485276b73543ea06f3c162243eb742e5d8997b9f6af4efe116e266a4ee0926da8f
6
+ metadata.gz: dce8d4bad7a8929816d81276e0e00ea95b06d3940f141e6e584bd3d093151f07648ee093e33de36243d7932550bdf6c0ea1d6913b00812f33a941ba67769cb2b
7
+ data.tar.gz: 5a234d7025ce558004a71c05f109127c414c875668c3bf98c5c56553dbf5c1201b1ebbcb6182074de47c73408c31895a019e1e597dcde609387c2c7e53fc7a6a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monitorsys-tortoise (0.1.4)
4
+ monitorsys-tortoise (0.1.7)
5
5
  activerecord
6
6
  fileutils
7
7
  honeybadger
@@ -0,0 +1,11 @@
1
+ unless ENV['TORTOISE_HONEYBADGER_API_KEY'].to_s.empty?
2
+ require 'honeybadger/ruby'
3
+
4
+ Honeybadger.configure do |config|
5
+ config.api_key = ENV['TORTOISE_HONEYBADGER_API_KEY'].to_s.strip
6
+ end
7
+
8
+ at_exit do
9
+ Honeybadger.stop
10
+ end
11
+ end
@@ -15,14 +15,16 @@ namespace :tortoise do
15
15
  t.string :public_informations_path
16
16
  t.string :user
17
17
  t.string :password
18
- t.integer :retry_time
19
18
  t.string :app_user
20
19
  t.string :app_password
20
+ t.integer :retry_time
21
+ t.integer :max_retry
21
22
  t.timestamps
22
23
  end
23
24
  create_table :invoices do |t|
24
25
  t.string :file
25
26
  t.string :status
27
+ t.integer :attempt_number
26
28
  t.timestamps
27
29
  end
28
30
  end
@@ -2,7 +2,6 @@ require 'listen'
2
2
  require 'rest-client'
3
3
  require 'fileutils'
4
4
  require 'mini_cache'
5
- require 'honeybadger' unless ENV['HONEYBADGER_API_KEY'].to_s.empty?
6
5
 
7
6
  require_relative '../config/sqllite3'
8
7
  require_relative 'tortoise/jobs/upload_job'
@@ -16,6 +15,7 @@ require_relative 'tortoise/services/bulk_loader'
16
15
  require_relative 'tortoise/services/initial_loader'
17
16
  require_relative 'tortoise/services/listener'
18
17
  require_relative 'tortoise/services/loader'
18
+ require_relative '../config/honeybadger'
19
19
 
20
20
  module Tortoise
21
21
 
@@ -25,22 +25,28 @@ module Tortoise
25
25
  private
26
26
 
27
27
  def process
28
- invoice.update(status: Invoice::STARTED)
28
+ invoice.update(status: Invoice::STARTED, attempt_number: invoice.attempt_number + 1)
29
+ api_helper.upload(invoice.file)
30
+ invoice.update(status: Invoice::DONE)
29
31
 
30
- begin
31
- api_helper.upload(invoice.file)
32
- invoice.update(status: Invoice::DONE)
32
+ puts "A nota #{invoice.file} foi enviada com sucesso!"
33
+ rescue StandardError => e
34
+ puts "Um erro aconteceu!", e
33
35
 
34
- puts "A nota #{invoice.file} foi enviada com sucesso!"
35
- rescue StandardError => e
36
- puts "Um erro aconteceu!", e
36
+ Honeybadger.notify(e, context: {
37
+ configuration: Tortoise::Configuration.all.map(&:to_s),
38
+ directories: Tortoise::Directory.all.map(&:to_s),
39
+ invoice: Tortoise::Invoice.where(id: invoice.id).map(&:to_s),
40
+ version: Tortoise::VERSION
41
+ }) unless ENV['TORTOISE_HONEYBADGER_API_KEY'].to_s.empty?
37
42
 
38
- Honeybadger.notify(e) unless ENV['HONEYBADGER_API_KEY'].to_s.empty?
43
+ invoice.update(status: Invoice::FAILED)
39
44
 
40
- invoice.update(status: Invoice::FAILED)
45
+ UploadJob.new(invoice.id).perform_in(configuration.default_retry_time) if retry?
46
+ end
41
47
 
42
- UploadJob.new(invoice.id).perform_in(configuration.default_retry_time)
43
- end
48
+ def retry?
49
+ invoice.attempt_number < configuration.default_max_retry
44
50
  end
45
51
 
46
52
  def invoice
@@ -20,6 +20,23 @@ module Tortoise
20
20
  (retry_time || 5).minutes
21
21
  end
22
22
 
23
+ def default_max_retry
24
+ max_retry || 5
25
+ end
26
+
27
+ def to_s
28
+ {
29
+ api_path: api_path,
30
+ token_path: token_path,
31
+ upload_path: upload_path,
32
+ public_informations_path: public_informations_path,
33
+ user: user,
34
+ password: read_attribute(:password),
35
+ app_user: app_user,
36
+ app_password: read_attribute(:app_password)
37
+ }
38
+ end
39
+
23
40
  private
24
41
 
25
42
  def crypt
@@ -2,6 +2,12 @@ module Tortoise
2
2
  class Directory < ApplicationRecord
3
3
  after_save :create_folder
4
4
 
5
+ def to_s
6
+ {
7
+ folder_path: folder_path
8
+ }
9
+ end
10
+
5
11
  private
6
12
 
7
13
  def create_folder
@@ -3,5 +3,13 @@ module Tortoise
3
3
  STARTED = 'started'
4
4
  DONE = 'done'
5
5
  FAILED = 'failed'
6
+
7
+ def to_s
8
+ {
9
+ file: file,
10
+ status: status,
11
+ attempt_number: attempt_number
12
+ }
13
+ end
6
14
  end
7
15
  end
@@ -9,7 +9,14 @@ module Tortoise
9
9
  def self.load(files)
10
10
  new(files).load
11
11
  rescue StandardError => e
12
- Honeybadger.notify(e) unless ENV['HONEYBADGER_API_KEY'].to_s.empty?
12
+ puts "Um erro aconteceu!", e
13
+
14
+ Honeybadger.notify(e, context: {
15
+ files: files,
16
+ configuration: Tortoise::Configuration.all.map(&:to_s),
17
+ directories: Tortoise::Directory.all.map(&:to_s),
18
+ version: Tortoise::VERSION
19
+ }) unless ENV['TORTOISE_HONEYBADGER_API_KEY'].to_s.empty?
13
20
  end
14
21
 
15
22
  def load
@@ -19,7 +19,7 @@ module Tortoise
19
19
  private
20
20
 
21
21
  def invoice
22
- @invoice ||= Tortoise::Invoice.create!(file: file, status: Invoice::STARTED)
22
+ @invoice ||= Tortoise::Invoice.create!(file: file, status: Invoice::STARTED, attempt_number: 0)
23
23
  end
24
24
 
25
25
  def exists?
@@ -1,3 +1,3 @@
1
1
  module Tortoise
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monitorsys-tortoise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Mangilli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-20 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -134,6 +134,7 @@ files:
134
134
  - Gemfile.lock
135
135
  - README.md
136
136
  - Rakefile
137
+ - config/honeybadger.rb
137
138
  - config/sqllite3.rb
138
139
  - lib/tasks/migrate.rake
139
140
  - lib/tortoise.rb