phonehome 0.0.27 → 0.0.28
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/lib/phonehome/gem/version.rb +1 -1
- data/lib/phonehome.rb +29 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f598d6f5bf9e8632d5bd2150b6c8c9e02de2c60
|
4
|
+
data.tar.gz: 68e494dd4fa1a8de605ea45322d7eb4a0b78cb3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46ca272e6fc1f1efbfad5435c6a92adb3cbf901ffae0566c92e428840d88226105cba4313ca5758bf3be8bbeb49a87887a9c4baaa58212248b73e44abb5b967f
|
7
|
+
data.tar.gz: f6a4526a5bef4e17248ae22bd50e2275311c30904dca311e96cb478c9edba33241bb628ef9c286d230a5ab4710eec4d2855ac940d3974cc234b0b5f4818114d0
|
data/lib/phonehome.rb
CHANGED
@@ -12,12 +12,18 @@ module Phonehome
|
|
12
12
|
@@phonehomeURL = url
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
#default debug to true for now
|
16
|
+
@@debugEnabled = true
|
17
|
+
def self.set_debug(debug)
|
18
|
+
@@debugEnabled = debug
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.call(secret_key, id, ) # id - from job, Event
|
16
22
|
begin
|
17
23
|
debug("Checking connection")
|
18
24
|
result = check_connection?{yield}
|
19
25
|
if result == false
|
20
|
-
|
26
|
+
puts('Phonehome not responding')
|
21
27
|
return false
|
22
28
|
end
|
23
29
|
debug("Checking secret key")
|
@@ -26,7 +32,7 @@ module Phonehome
|
|
26
32
|
user_events = get_user_events(secret_key).split
|
27
33
|
status = user_events.include?(id.to_s) ? true : false
|
28
34
|
if status == false
|
29
|
-
|
35
|
+
puts('You try to run not your event!') # Write error to console
|
30
36
|
yield
|
31
37
|
exit
|
32
38
|
end
|
@@ -48,11 +54,12 @@ module Phonehome
|
|
48
54
|
end
|
49
55
|
|
50
56
|
def self.start(secret_key, id) # id - from job, Event
|
57
|
+
debug("Starting #{secret_key} #{id}")
|
51
58
|
begin_time = Time.now
|
52
59
|
app_name = get_app_name(id)
|
53
60
|
response = excon_post_json("http://#{@@phonehomeURL}/query/#{secret_key}/#{get_status(1)}/#{id}")
|
54
61
|
if JSON.parse(response.body)['status'] == 'All events are completed'
|
55
|
-
|
62
|
+
puts "#{id}: All events are completed"
|
56
63
|
yield
|
57
64
|
raise "#{id}: All events are completed"
|
58
65
|
end
|
@@ -60,10 +67,12 @@ module Phonehome
|
|
60
67
|
job_info = JobInfo.new(JSON.parse(response.body)['id'], JSON.parse(response.body)['status'], begin_time)
|
61
68
|
@events_info[id] = job_info
|
62
69
|
|
70
|
+
debug("job info #{id} #{job_info}")
|
63
71
|
job_info
|
64
72
|
end
|
65
73
|
|
66
74
|
def self.stop(id,result_of_work = nil)
|
75
|
+
debug("Stopping #{id}")
|
67
76
|
finish = Time.now
|
68
77
|
status = 'completed'
|
69
78
|
|
@@ -73,20 +82,24 @@ module Phonehome
|
|
73
82
|
status = 'late_completed'
|
74
83
|
end
|
75
84
|
|
85
|
+
debug("Stopping #{id} #{status}")
|
86
|
+
|
76
87
|
text = "#{finish.to_i - job_info.begin_time.to_i} secs"
|
77
88
|
if (result_of_work.nil?)
|
78
89
|
# text =
|
79
90
|
else
|
80
91
|
text = result_of_work.to_s + " (" + text + ")"
|
81
92
|
end
|
93
|
+
debug("Stopping text.size #{text.size}")
|
82
94
|
excon_post("http://#{@@phonehomeURL}/query_update/#{job_info.api_job_id}/#{status}/#{URI.encode_www_form('result' => text)}")
|
83
95
|
else
|
84
|
-
|
96
|
+
debug("Event with id '#{id}' not found in events_info")
|
85
97
|
pp events_info
|
86
98
|
end
|
87
99
|
end
|
88
100
|
|
89
101
|
def self.send_error(id, e)
|
102
|
+
debug("Error #{id}")
|
90
103
|
if @events_info.include?(id)
|
91
104
|
job_info = @events_info[id]
|
92
105
|
excon_post("http://#{@@phonehomeURL}/query_update/#{job_info.api_job_id}/failed/#{URI.encode_www_form('error' => e)}")
|
@@ -107,7 +120,7 @@ module Phonehome
|
|
107
120
|
def self.check_secret_key(secret_key)
|
108
121
|
response = excon_post("http://#{@@phonehomeURL}/check_secret_key/#{secret_key}")
|
109
122
|
if response.data[:body] != 'true'
|
110
|
-
|
123
|
+
puts 'Your secret key is invalid!'
|
111
124
|
yield
|
112
125
|
exit
|
113
126
|
end
|
@@ -117,7 +130,7 @@ module Phonehome
|
|
117
130
|
begin
|
118
131
|
response = excon_get("http://#{@@phonehomeURL}")
|
119
132
|
rescue Excon::Errors::SocketError => error
|
120
|
-
|
133
|
+
puts "#{error} - Server not responding"
|
121
134
|
sleep(5)
|
122
135
|
retry
|
123
136
|
end
|
@@ -137,18 +150,21 @@ module Phonehome
|
|
137
150
|
end
|
138
151
|
end
|
139
152
|
|
153
|
+
#add retry logic
|
140
154
|
def self.excon_post(url)
|
141
|
-
debug("
|
155
|
+
debug("POST #{url}")
|
142
156
|
Excon.post(url)
|
143
157
|
end
|
144
158
|
|
159
|
+
#add retry logic
|
145
160
|
def self.excon_post_json(url)
|
146
|
-
debug("
|
161
|
+
debug("POST JSON #{url}")
|
147
162
|
Excon.post(url, :headers => { "Content-Type" => "application/json" })
|
148
163
|
end
|
149
164
|
|
165
|
+
#add retry logic
|
150
166
|
def self.excon_get(url)
|
151
|
-
debug("
|
167
|
+
debug("POST #{url}")
|
152
168
|
Excon.get(url)
|
153
169
|
end
|
154
170
|
|
@@ -161,7 +177,9 @@ module Phonehome
|
|
161
177
|
end
|
162
178
|
|
163
179
|
def self.debug(message)
|
164
|
-
|
180
|
+
if @@debugEnabled
|
181
|
+
puts("PH:DEBUG:"+message)
|
182
|
+
end
|
165
183
|
end
|
166
184
|
|
167
185
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phonehome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- info@phonehome.io
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|