holistics 0.3.0 → 0.3.1

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
- SHA1:
3
- metadata.gz: 971907f72fa1cd5696fcb351d9c3ef571a40990e
4
- data.tar.gz: 865601ab1b96aba716d23ddec7eb3a13db454100
2
+ SHA256:
3
+ metadata.gz: d37b04f209ce3578a3d08d7854d6c5ed15950c772ac5298a2b5ce9f591404d82
4
+ data.tar.gz: dea733b1f41dd4fd48a2216db0f04f9b8d02eed1d31666e3b778dbfdad77bd79
5
5
  SHA512:
6
- metadata.gz: 47788d94da15628c6100e653c4bb371c07e245fe0733dfbc039a101ff6a8f806123e98a76c188e49d31c3f1b6a2cb8414a3a17a2a77bf8ef51c50395ca651d02
7
- data.tar.gz: e9db1824bdd8a394de9cad3e2d592bb4f03891d40539b860d7a8eccd3b54f94fa1bd11db834378a781e80f639bf9ed9ed39350ce074b210af4b539d23312b4fa
6
+ metadata.gz: 13e878fe25977f683c37444f9b6518b50e0e3e428714e8203df958c1809f6a042575641efb3e3193d37c9960a91b04761f13ad80b7b5833e3acb0610034a27e4
7
+ data.tar.gz: e63194d1bad41ceb4a39b06c4d83d1b6892a018c0368fc1cb122e8cf47d64b85d1408b3f0e07b38eba4a877898a867295887bc0688b32941430697b145519f33
data/CHANGELOG.md CHANGED
@@ -23,3 +23,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
23
23
  ## v0.2.6
24
24
  * Add error handling and retry mechanism for `fetch_job_details`
25
25
 
26
+ ## v0.3.0
27
+ * Add option to execute Data Imports in custom range mode
28
+
29
+ ## v0.3.1
30
+ * Add option to split a custom range Data Import execution into smaller ones
@@ -7,6 +7,8 @@ require 'holistics/helpers/job_manager'
7
7
 
8
8
  module Holistics
9
9
  class ApiClient
10
+ class ImportError < StandardError
11
+ end
10
12
 
11
13
  def import_csv options
12
14
  local_filepath = options[:filepath]
@@ -89,6 +91,10 @@ module Holistics
89
91
 
90
92
  puts "Job submitted. Job ID: #{job_id}."
91
93
  job_manager.tail_logs job_id
94
+ res = job_manager.fetch_job_results job_id
95
+ unless res['status'] == 'success'
96
+ raise ImportError.new("Failed Import Job #{job_id}: #{res['error']}")
97
+ end
92
98
  end
93
99
 
94
100
  def job_show(options)
@@ -9,10 +9,10 @@ module Holistics
9
9
 
10
10
  def fetch_job_details(job_id, last_id = 0)
11
11
  tries ||= MAX_RETRIES
12
-
12
+
13
13
  url = auth_helper.api_url_for("jobs/#{job_id}/logs.json", last_id: last_id)
14
- response = HttpRequest.new.simple_get url
15
-
14
+ response = http_request.simple_get url
15
+
16
16
  JSON.parse(response.body)
17
17
  rescue JSON::ParserError => err
18
18
  sleep 2 ** (MAX_RETRIES - tries) unless Holistics.test?
@@ -24,6 +24,11 @@ module Holistics
24
24
  raise
25
25
  end
26
26
 
27
+ def fetch_job_results(job_id)
28
+ url = "jobs/#{job_id}/get_results.json"
29
+ http_request.get(url, "Cannot fetch info of job #{job_id}")
30
+ end
31
+
27
32
  def job_show options
28
33
  job_id = options[:job_id]
29
34
  tail_logs(job_id)
@@ -47,6 +52,12 @@ module Holistics
47
52
  ts = Time.parse(log['timestamp'])
48
53
  Holistics.logger.log(log['level'], log['message'], timestamp: ts)
49
54
  end
55
+
56
+ private
57
+
58
+ def http_request
59
+ @http_request ||= HttpRequest.new
60
+ end
50
61
  end
51
62
  end
52
63
  end
@@ -1,4 +1,4 @@
1
1
  module Holistics
2
- VERSION = '0.3.0'
3
- DATE = '2017-10-27'
2
+ VERSION = '0.3.1'
3
+ DATE = '2018-08-24'
4
4
  end
data/lib/import.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'colorize'
2
3
 
3
4
  module Holistics
4
5
  class Import < Thor
@@ -18,6 +19,7 @@ module Holistics
18
19
  method_option :custom_range, aliases: '--custom-range', type: :boolean, lazy_default: true, required: false, desc: 'Execution type is custom_range. The range of left-closed right-opened range `[start, end)`.'
19
20
  method_option :range_start, aliases: '--range-start', type: :string, required: false, desc: 'start range'
20
21
  method_option :range_end, aliases: '--range-end', type: :string, required: false, desc: 'end range'
22
+ method_option :split_mode, aliases: '--split-mode', type: :string, required: false, desc: "Import splitting mode. Use 'daily' to split your custom range import to multiple executions, each covering one day of data."
21
23
  desc 'execute', 'Invoke an import job'
22
24
 
23
25
  def execute
@@ -30,8 +32,14 @@ module Holistics
30
32
  params[:range_start] = options[:range_start]
31
33
  params[:range_end] = options[:range_end]
32
34
  params[:execution_mode] = 'custom_range'
35
+ if options[:split_mode] == 'daily'
36
+ return daily_splitted_import(params.dup)
37
+ end
33
38
  end
34
- api_client.send_import(params.dup)
39
+ send_import(params)
40
+ rescue => e
41
+ STDERR.puts e.message.red
42
+ exit 1
35
43
  end
36
44
 
37
45
  no_commands do
@@ -39,5 +47,36 @@ module Holistics
39
47
  @api_client ||= ApiClient.new
40
48
  end
41
49
  end
50
+
51
+ private
52
+
53
+ def daily_splitted_import(params)
54
+ start_date = Date.parse(params[:range_start]) rescue raise("Invalid range start")
55
+ if params[:range_end]
56
+ end_date = Date.parse(params[:range_end]) rescue raise("Invalid range end")
57
+ else
58
+ end_date = Date.today
59
+ end
60
+ while start_date + 1 < end_date
61
+ params[:range_start] = start_date.strftime('%Y-%m-%d')
62
+ params[:range_end] = (start_date + 1).strftime('%Y-%m-%d')
63
+ puts "Importing range '#{params[:range_start]}' - '#{params[:range_end]}'".green
64
+ send_import(params, tries: 2)
65
+ start_date = start_date + 1
66
+ end
67
+ end
68
+
69
+ def send_import(params, tries: 0)
70
+ total_trials ||= tries
71
+ api_client.send_import(params.dup)
72
+ rescue ApiClient::ImportError => e
73
+ sleep 2 ** (total_trials - tries) unless Holistics.test?
74
+ if (tries -= 1) >= 0
75
+ puts 'Retrying...'.orange
76
+ retry
77
+ end
78
+ puts "Exceeded retry count of #{total_trials}...".orange if total_trials > 0
79
+ raise
80
+ end
42
81
  end
43
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thanh Dinh Khac
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-27 00:00:00.000000000 Z
12
+ date: 2018-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.5.1
131
+ rubygems_version: 2.7.7
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: CLI interface for Holistics