monitorsys-tortoise 0.1.0 → 0.1.1
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 +4 -4
- data/.gitignore +0 -1
- data/lib/tortoise/jobs/upload_job.rb +26 -5
- data/lib/tortoise/services/bulk_loader.rb +6 -5
- data/lib/tortoise/services/initial_loader.rb +1 -1
- data/lib/tortoise/services/loader.rb +14 -5
- data/lib/tortoise/version.rb +1 -1
- data/monitorsys-tortoise-0.1.0.gem +0 -0
- metadata +3 -3
- data/bin/console +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24fa5667336b7e80ae1b10d2e19fd0a04074c9518ceb88f589ce42fed72cccfb
|
4
|
+
data.tar.gz: eebcab7a46f1519cb23e3b9203daef3bba56d6be1ee92ab32b5150c1fc6ccd42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e751c10c22d0c6d07ce3585123011dd6c634b87d5420ee1f7a87e53b989196e63b09998d5dd0d61cf64564c2565bb485011c81d2275b3e464a79bf29d8ba26
|
7
|
+
data.tar.gz: 37c598d3ce0efc914c76f2030d5fc88e7477a96cc126ac71d14e91feda19a73aea7e72176e8ac7ed892b5e267ff9df86ecc162cf4bc1bf2d2973877fd4fecf25
|
data/.gitignore
CHANGED
@@ -1,10 +1,30 @@
|
|
1
1
|
module Tortoise
|
2
2
|
class UploadJob
|
3
|
-
|
3
|
+
attr_reader :invoice_id
|
4
|
+
|
5
|
+
def initialize(invoice_id)
|
6
|
+
@invoice_id = invoice_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def perform_now
|
10
|
+
process
|
11
|
+
end
|
12
|
+
|
13
|
+
def perform_in(delay=0)
|
4
14
|
Thread.new do
|
5
15
|
sleep delay
|
6
16
|
|
7
|
-
|
17
|
+
process
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def perform
|
22
|
+
perform_in
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def process
|
8
28
|
invoice.update(status: Invoice::STARTED)
|
9
29
|
|
10
30
|
begin
|
@@ -19,12 +39,13 @@ module Tortoise
|
|
19
39
|
|
20
40
|
invoice.update(status: Invoice::FAILED)
|
21
41
|
|
22
|
-
UploadJob.new
|
42
|
+
UploadJob.new(invoice.id).perform_in(configuration.default_retry_time)
|
23
43
|
end
|
24
44
|
end
|
25
|
-
end
|
26
45
|
|
27
|
-
|
46
|
+
def invoice
|
47
|
+
@invoice ||= Tortoise::Invoice.find(invoice_id)
|
48
|
+
end
|
28
49
|
|
29
50
|
def api_helper
|
30
51
|
@api_helper ||= Tortoise::ApiHelper.new
|
@@ -1,20 +1,21 @@
|
|
1
1
|
module Tortoise
|
2
2
|
class BulkLoader
|
3
|
-
attr_reader :files
|
3
|
+
attr_reader :files, :async
|
4
4
|
|
5
|
-
def initialize(files)
|
5
|
+
def initialize(files, async: true)
|
6
6
|
@files = files
|
7
|
+
@async = async
|
7
8
|
end
|
8
9
|
|
9
|
-
def self.load(files)
|
10
|
-
new(files).load
|
10
|
+
def self.load(files, async: true)
|
11
|
+
new(files, async: async).load
|
11
12
|
rescue StandardError => e
|
12
13
|
Honeybadger.notify(e) unless ENV['HONEYBADGER_API_KEY'].to_s.empty?
|
13
14
|
end
|
14
15
|
|
15
16
|
def load
|
16
17
|
files.each do |file|
|
17
|
-
Tortoise::Loader.load(file)
|
18
|
+
Tortoise::Loader.load(file, async: async)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -1,23 +1,32 @@
|
|
1
1
|
module Tortoise
|
2
2
|
class Loader
|
3
|
-
attr_reader :file
|
3
|
+
attr_reader :file, :async
|
4
4
|
|
5
|
-
def initialize(file)
|
5
|
+
def initialize(file, async: true)
|
6
6
|
@file = file
|
7
|
+
@async = async
|
7
8
|
end
|
8
9
|
|
9
|
-
def self.load(file)
|
10
|
-
new(file).load
|
10
|
+
def self.load(file, async: true)
|
11
|
+
new(file, async: async).load
|
11
12
|
end
|
12
13
|
|
13
14
|
def load
|
14
15
|
return if exists?
|
15
16
|
|
16
|
-
|
17
|
+
upload_job.try(job_method)
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
20
21
|
|
22
|
+
def upload_job
|
23
|
+
Tortoise::UploadJob.new(invoice.id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def job_method
|
27
|
+
async ? :perform : :perform_now
|
28
|
+
end
|
29
|
+
|
21
30
|
def invoice
|
22
31
|
@invoice ||= Tortoise::Invoice.create!(file: file, status: Invoice::STARTED)
|
23
32
|
end
|
data/lib/tortoise/version.rb
CHANGED
Binary file
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2021-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -22,7 +22,6 @@ files:
|
|
22
22
|
- Gemfile.lock
|
23
23
|
- README.md
|
24
24
|
- Rakefile
|
25
|
-
- bin/console
|
26
25
|
- config/sqllite3.rb
|
27
26
|
- lib/tasks/migrate.rake
|
28
27
|
- lib/tortoise.rb
|
@@ -38,6 +37,7 @@ files:
|
|
38
37
|
- lib/tortoise/services/listener.rb
|
39
38
|
- lib/tortoise/services/loader.rb
|
40
39
|
- lib/tortoise/version.rb
|
40
|
+
- monitorsys-tortoise-0.1.0.gem
|
41
41
|
- tortoise.gemspec
|
42
42
|
homepage: http://monitorsys.com.br
|
43
43
|
licenses: []
|
data/bin/console
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'irb'
|
3
|
-
require 'tortoise'
|
4
|
-
require 'io/console'
|
5
|
-
|
6
|
-
def get_response(answer, default: nil, password: false)
|
7
|
-
puts "#{answer} (#{default || 'n/a'}): "
|
8
|
-
chomp(password).presence || default
|
9
|
-
end
|
10
|
-
|
11
|
-
def chomp(password)
|
12
|
-
password ? STDIN.noecho(&:gets).chomp : gets.chomp
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_directory
|
16
|
-
Tortoise::Directory.create!(folder_path: get_response('Digite o diretorio da pasta'))
|
17
|
-
|
18
|
-
create_directory if get_response('Deseja cadastrar outro diretorio?(S/N)').to_s.upcase == 'S'
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_configuration
|
22
|
-
Tortoise::Configuration.create!(
|
23
|
-
api_path: ENV['TORTOISE_API_PATH'].to_s.strip,
|
24
|
-
token_path: ENV['TORTOISE_TOKEN_PATH'].to_s.strip,
|
25
|
-
upload_path: ENV['TORTOISE_UPLOAD_PATH'].to_s.strip,
|
26
|
-
public_informations_path: ENV['TORTOISE_PUBLIC_INFORMATIONS_PATH'].to_s.strip,
|
27
|
-
user: get_response('Digite o usuario'),
|
28
|
-
password: get_response('Digite a senha', password: true),
|
29
|
-
retry_time: ENV['TORTOISE_RETRY_TIME'].to_s.strip,
|
30
|
-
app_user: ENV['TORTOISE_APP_USER'].to_s.strip,
|
31
|
-
app_password: ENV['TORTOISE_APP_PASSWORD'].to_s.strip
|
32
|
-
)
|
33
|
-
|
34
|
-
Tortoise::InitialLoader.new.load
|
35
|
-
end
|
36
|
-
|
37
|
-
create_directory unless Tortoise::Configuration.exists?
|
38
|
-
create_configuration unless Tortoise::Configuration.exists?
|
39
|
-
|
40
|
-
Tortoise::Listener.new.start
|
41
|
-
|
42
|
-
# IRB.start(__FILE__)
|
43
|
-
sleep
|