holistics-cli 0.1.2 → 0.2.0

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
  SHA1:
3
- metadata.gz: ef9b9ce12830adf846878dd595dc9c57a10d8322
4
- data.tar.gz: 14026763884c485018035f90a23895c70718061f
3
+ metadata.gz: 763f03645d0cb884b8ed479c3da2780552671e24
4
+ data.tar.gz: be1f71741967b9c431afaec34575f2296c464236
5
5
  SHA512:
6
- metadata.gz: 8154a55fe4ad764e16e1e43116baf633a36798ddc973a670cc74ee2ef600f4de4154b74859e8387682e7aa3cfa809fcf319400763229cb2ab6cd4a8959029e18
7
- data.tar.gz: 2588471ece3e5235ee26baa5ca95ae163956d60be5002b6abdea2383ecab9b111c36ebfbc1cddc69e1a756ded98f4a15e6205ca9b9bfe4c7582a9163ffdf36d8
6
+ metadata.gz: bc2eaea5ddcfeb4aebee7d05ca9d558ee847bddcf87ef005c94e97eb14c5438fb7c1a1e942750dbdcf7ea2a2bbe1ea8a7d1a664ec1f6e2514a287be4858f3c0a
7
+ data.tar.gz: 7d270cd11e0be8ce7ea3eace4e0d6615a96859c6ef523aaa31a60e26d0633e5b9e580297d4b47a6c3b0dea191dd2d393af463e7bc740eb11ebce06ca7eb84960
@@ -1,3 +1,8 @@
1
+ ## 0.2.0, release 2017-09-29
2
+ * Bug fix: unable to config token
3
+
4
+ * Add `job cancel` command
5
+
1
6
  ## 0.1.2, release 2017-08-17
2
7
  * Bug fixes
3
8
 
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 TODO: Write your name
3
+ Copyright (c) 2017 pmint93
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Holistics CLI
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/holistics-cli.svg)](https://badge.fury.io/rb/holistics-cli)
3
+ [![Gem Version](https://badge.fury.io/rb/holistics-cli.svg)](https://badge.fury.io/rb/holistics-cli) [![Test Coverage](https://codeclimate.com/github/pmint93/holistics-cli/badges/coverage.svg)](https://codeclimate.com/github/pmint93/holistics-cli/coverage) [![Code Climate](https://codeclimate.com/github/pmint93/holistics-cli/badges/gpa.svg)](https://codeclimate.com/github/pmint93/holistics-cli) [![Issue Count](https://codeclimate.com/github/pmint93/holistics-cli/badges/issue_count.svg)](https://codeclimate.com/github/pmint93/holistics-cli)
4
4
 
5
5
  CommandLine Interface to [Holistics API](https://docs.holistics.io/api/)
6
6
 
7
- > Dislaim: The official Holistics-CLI is quite limit for me, so I made this gem as an alternative
7
+ > Disclaim: The official Holistics-CLI is quite limit for me, so I made this gem as an alternative
8
8
 
9
9
  :warning: This gem use the same command `holistics` as [Official Holistics-CLI](https://docs.holistics.io/holistics-cli/), so it may confict if both installed.
10
10
 
@@ -49,4 +49,4 @@ Everyone interacting in the Holistics-CLI project’s codebases, issue trackers,
49
49
 
50
50
  ## Related
51
51
 
52
- * [Official Holistics-CLI](https://docs.holistics.io/holistics-cli/)
52
+ * [Official Holistics-CLI](https://docs.holistics.io/holistics-cli/)
@@ -56,7 +56,7 @@ module Holistics
56
56
  unless token
57
57
  current_config = configured? ? read_config : {}
58
58
  current_token = current_config[:token]
59
- new_token = ask "Your Holistics token [#{current_token.light_black}]: "
59
+ new_token = ask "Your Holistics token [#{current_token.to_s.light_black}]: "
60
60
  new_token = nil if new_token.blank?
61
61
  unless token = new_token || current_token
62
62
  STDERR.puts 'Failed to config, empty token provided !'
@@ -25,6 +25,19 @@ module Holistics
25
25
  [response.status, response.body]
26
26
  end
27
27
 
28
+ def put(path, options = {})
29
+ options[:params] ||= {}
30
+ options[:headers] ||= {}
31
+ options[:headers].merge!('Content-Type': 'application/json')
32
+ response = @conn.put do |req|
33
+ req.url path
34
+ req.headers.merge!(options[:headers])
35
+ req.params['_utoken'] = @token
36
+ req.body = options[:params].to_s
37
+ end
38
+ [response.status, response.body]
39
+ end
40
+
28
41
  def post(path, options = {})
29
42
  options[:params] ||= {}
30
43
  options[:headers] ||= {}
@@ -61,9 +61,8 @@ Examples:
61
61
  def execute(id)
62
62
  puts "`imports execute #{id}` called with options: #{options}" if Holistics.debug?
63
63
  result = @this.execute(id)
64
- puts 'Job ID: ' + result['job_id'].to_s.yellow
65
- puts 'Status: ' + Holistics::Utils.colorize(result['status'])
66
- invoke 'holistics:jobs:logs', [result['job_id']], { watch: true }
64
+ puts 'Job ID: ' + result['job_id'].to_s.yellow + " Submit: " + Holistics::Utils.colorize(result['status'])
65
+ invoke 'holistics:jobs:logs', [result['job_id']], { follow: true }
67
66
  end
68
67
  map %w[exec] => :execute
69
68
 
@@ -61,35 +61,49 @@ Examples:
61
61
  method_option :number, aliases: '-n', desc: 'Only print number of last lines', type: :numeric
62
62
  def logs(id)
63
63
  puts "`jobs logs #{id}` called with options: #{options}" if Holistics.debug?
64
- if options[:watch]
64
+ if options[:follow]
65
65
  last_id = 0
66
66
  loop do
67
67
  data = @this.logs(id, { 'last_id': last_id })
68
- print_logs(data['logs'])
68
+ print_logs(id, data['logs'])
69
69
  last_id = data['logs'].last['id'] if data['logs'].length > 0
70
70
  break unless data['has_more']
71
71
  sleep 0.5
72
72
  end
73
73
  else
74
74
  data = @this.logs(id)
75
- print_logs(data['logs'], options[:number])
75
+ print_logs(id, data['logs'], options[:number])
76
76
  end
77
77
  end
78
78
 
79
- # desc 'cancel', 'Cancel a running job'
80
- # def cancel(id)
81
- # puts "Comming soon".yellow
82
- # end
79
+ desc 'cancel', 'Cancel a running job'
80
+ def cancel(id)
81
+ puts "`jobs cancel #{id}` called with options: #{options}" if Holistics.debug?
82
+ print "Cancelling Job #{id} ...".yellow
83
+ result = @this.cancel(id)
84
+ if result['status'].to_s.upcase == 'OK'
85
+ loop do
86
+ job_info = @this.find(id)
87
+ unless job_info['status'] == 'cancelling'
88
+ puts Holistics::Utils.colorize(job_info['status'])
89
+ break
90
+ end
91
+ sleep 0.5
92
+ end
93
+ else
94
+ puts "Failed to cancel the job #{id}".red
95
+ end
96
+ end
83
97
 
84
98
  private
85
99
 
86
- def print_logs(log_lines, line_count = 0)
100
+ def print_logs(job_id, log_lines, line_count = 0)
87
101
  line_count ||= 0
88
102
  log_lines ||= []
89
103
  log_lines[(-[line_count, log_lines.length].min)..-1]
90
104
  log_lines.each do |log_line|
91
105
  t = log_line['timestamp'] || Time.now.utc
92
- puts "#{t}; #{log_line['level']}: #{log_line['message']}"
106
+ puts "[#{t} ##{job_id}] #{log_line['level']}: #{log_line['message']}"
93
107
  end
94
108
  end
95
109
 
@@ -5,6 +5,11 @@ module Holistics
5
5
  status, body = @client.get("/jobs/#{id}/logs.json", { params: params })
6
6
  handle_http_result(status, body)
7
7
  end
8
+
9
+ def cancel(id, params = {})
10
+ status, body = @client.put("/jobs/#{id}/cancel.json", { params: params })
11
+ handle_http_result(status, body)
12
+ end
8
13
  end
9
14
  end
10
15
  end
@@ -38,7 +38,7 @@ Examples:
38
38
  puts "`transforms execute #{id}` called with options: #{options}" if Holistics.debug?
39
39
  result = @this.execute(id)
40
40
  puts 'Job ID: ' + result['job_id'].to_s.yellow + " Submit: " + Holistics::Utils.colorize(result['status'])
41
- invoke 'holistics:jobs:logs', [result['job_id']], { watch: true }
41
+ invoke 'holistics:jobs:logs', [result['job_id']], { follow: true }
42
42
  end
43
43
  map %w[exec] => :execute
44
44
 
@@ -4,7 +4,7 @@ module Holistics
4
4
  COLORIZE_MAPPING = {
5
5
  green: %w{active success ok},
6
6
  red: %w{fail failure error cancelled},
7
- yellow: %w{new running pending unknown}
7
+ yellow: %w{new running pending unknown cancelling}
8
8
  }
9
9
  def colorize(text)
10
10
  color = COLORIZE_MAPPING.find { |color, values| values.include?(text) }
@@ -1,3 +1,3 @@
1
1
  module Holistics
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holistics-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thanh Pham Minh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-17 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  version: '0'
192
192
  requirements: []
193
193
  rubyforge_project:
194
- rubygems_version: 2.6.12
194
+ rubygems_version: 2.6.13
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Holistics CommandLine Interface