navilocal 0.0.9 → 1.0.0

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: 14eebe3430a78024693c96561e48ca9993e940530469310505b107da3c57c793
4
- data.tar.gz: 03354ca57e0e15a1f34be7f8f337ef2950e851c87f2390a6b75ddf5f345ace63
3
+ metadata.gz: 428854cbf081cf3618d3bb45026080cc3b507627288bcbf50922a347d9f88256
4
+ data.tar.gz: 1f18f7e950fba484d35c38730c4cc21564825b362694e7bb1c2d3993dbeadaa9
5
5
  SHA512:
6
- metadata.gz: 04c5b3c5f0d9bcb07591e94bacb15215fd56b9eed63a961cdf59332f944d9829d546bf3fa55b307a41b702c9f6dc002842640004d25900fe0bed52d60b1dea36
7
- data.tar.gz: 0f6212817566b6cf1afb47fc85689d401ad4e45d772adcefc8db96d84c0f1030bf81f952f1277cdeb3e617a9f02608764dfe16a34e7963dec5cb60050ead8238
6
+ metadata.gz: 0c889e499760a6e755c0dd8d69687cea89d8648ac6ef1705693038e62fa6c0cc7e8740e111f51ac4cb975acacc5ccee9d7eb03f250b860d842d7e7503dc23e0b
7
+ data.tar.gz: 19a4a6c6148114d1b4539a76dba44e6ce640e3135e75f3d3a3d7a58791bb95314f6a60e814a67d44d35f9b27a2311744ae2e471e0f40b05e0d3d293ff54294ef
@@ -9,6 +9,11 @@ module NaviClientInstaller
9
9
 
10
10
  DEFAULT_STORAGE = File.expand_path File.join('~', '.navi')
11
11
 
12
+ SSO_URL = "https://signin.navihq.com"
13
+ GENERATE_CSV_URL = "https://api2.navihq.com/v2/generate_csv_input"
14
+
15
+
16
+
12
17
  attr_accessor *PROPERTIES
13
18
 
14
19
  def initialize(options = {})
@@ -50,11 +50,7 @@ module NaviClientInstaller
50
50
  end
51
51
 
52
52
  @refresh_btn.signal_connect 'clicked' do |button|
53
- terminate_worker_thread
54
- @logger.debug "Restarting the process"
55
- @stop_btn.set_sensitive true
56
- start
57
- @notifier.label = "Restarting.."
53
+ restart_process
58
54
  end
59
55
 
60
56
  @window_ui.signal_connect("destroy") {|button|
@@ -76,16 +72,26 @@ module NaviClientInstaller
76
72
 
77
73
  def terminate_worker_thread
78
74
  stop_naviai
75
+ @imap&.disconnect unless @imap&.disconnected?
79
76
  @worker_thread&.terminate if @worker_thread&.alive?
80
77
 
81
78
  end
82
79
 
80
+ def restart_process terminate_worker = true
81
+ terminate_worker_thread if terminate_worker
82
+ @logger.debug "Restarting the process"
83
+ @notifier.label = "Restarting.."
84
+ @stop_btn.set_sensitive true
85
+ start
86
+
87
+ end
88
+
83
89
 
84
90
  def start_fetching
85
91
 
86
92
  env = "development"
87
- sso_web_url = "https://signin.navihq.com"
88
- gen_csv_url = "https://api2.navihq.com/v2/generate_csv_input"
93
+ sso_web_url = NaviClientInstaller::Settings::SSO_URL
94
+ gen_csv_url = NaviClientInstaller::Settings::GENERATE_CSV_URL
89
95
 
90
96
  @client = NaviClient::Local.new(sso_web_url, "local", gen_csv_url, true, env)
91
97
  @client.set_token "Token: #{@token}##{@settings.username}"
@@ -98,34 +104,36 @@ module NaviClientInstaller
98
104
  @client.setupLoggly("navi-client")
99
105
  end
100
106
 
101
- @logger.debug "Running the process.. #{@token}"
107
+ @logger.debug "Running the process.."
102
108
  @logger.debug "Connecting to imap server with your local config."
103
109
 
104
110
  @notifier.label = "Configuring the system.."
105
- @imap = @client.imap_connection(@settings.provider, @settings.username, @settings.password, false) if @imap.nil?
111
+ begin
112
+
113
+ @imap = @client.imap_connection(@settings.provider, @settings.username, @settings.password, false)
114
+
115
+ if @client.errors.nil?
106
116
 
107
- if @client.errors.nil?
117
+ @logger.debug "Complete. OK..."
108
118
 
109
- @logger.debug "Complete. OK..."
119
+ filenames = []
120
+ dateStarted = DateTime.now
121
+ @logger.debug "Syncing started at #{dateStarted}"
122
+ @client.logToLoggly({event:"EMAIL_SYNC_STARTED", env: env, storage: "local", email: @settings.username})
110
123
 
111
- filenames = []
112
- dateStarted = DateTime.now
113
- @logger.debug "Syncing started at #{dateStarted}"
114
- @client.logToLoggly({event:"EMAIL_SYNC_STARTED", env: env, storage: "local", email: @settings.username})
124
+ sendEmailCompletedEvent = true
125
+ folder = "Inbox"
115
126
 
116
- sendEmailCompletedEvent = true
117
- folder = "Inbox"
127
+ #this block of code is repeated. Need to change in navi_client gem for that
128
+ @imap.examine folder
129
+ total = @imap.uid_search(['ALL']).size
130
+ downloaded = @client.getMessageUUIds("#{@settings.download_path}#{@settings.username}/meta/").size
131
+ downloaded = downloaded - 2 if downloaded > 1
118
132
 
119
- #this block of code is repeated. Need to change in navi_client gem for that
120
- @imap.examine folder
121
- total = @imap.uid_search(['ALL']).size
122
- downloaded = @client.getMessageUUIds("#{@settings.download_path}#{@settings.username}/meta/").size
123
- downloaded = downloaded - 2 if downloaded > 1
133
+ @email_indicator.label = "#{downloaded}/#{total}"
124
134
 
125
- @email_indicator.label = "#{downloaded}/#{total}"
126
135
 
127
- begin
128
- # start_naviai
136
+ # start_naviai
129
137
  @notifier.label = "Checking for previous failures.."
130
138
 
131
139
  start_naviai
@@ -181,15 +189,14 @@ module NaviClientInstaller
181
189
  @notifier.label = "Waiting for the new emails.."
182
190
  @client.idle_loop(@imap, ['UNSEEN'], folder, @settings.provider, @settings.username, @settings.password)
183
191
 
184
- @imap.logout
185
- @imap.disconnect
186
192
 
187
- rescue => e
188
- @logger.debug "#{e.message}"
189
- end
190
193
 
191
- else
192
- @logger.debug "Failed to connect with your email. Please recheck the configuration."
194
+ else
195
+ @logger.debug "Failed to connect with your email. Please recheck the configuration."
196
+ end
197
+ rescue => e
198
+ @logger.debug "#{e.message}"
199
+ restart_process false
193
200
  end
194
201
 
195
202
  end
@@ -204,25 +211,20 @@ module NaviClientInstaller
204
211
  end
205
212
 
206
213
  def start_naviai
214
+ stop_naviai
207
215
  navi_path = NaviClientInstaller::Settings::DEFAULT_STORAGE
208
-
209
- pid = spawn("#{navi_path}/bin/naviai", :out => "#{navi_path}/bin/test.out", :err => "#{navi_path}/bin/test.err")
210
-
211
- File.open("#{navi_path}/bin/naviai_pid.tmp", 'w') { |file| file.write(pid) }
212
-
213
- Process.detach(pid)
216
+ system("#{navi_path}/bin/naviai &")
217
+ sleep 1
214
218
  end
215
219
 
216
220
  def stop_naviai
217
221
  # kill naviai process
218
- navi_path = File.join NaviClientInstaller::Settings::DEFAULT_STORAGE , 'bin', 'naviai_pid.tmp'
222
+ naviPid = Integer(%x(lsof -i tcp:9090 | grep naviai | awk {'print $2'})) rescue false
219
223
  begin
220
- Process.kill('QUIT', File.read(navi_path).to_i) if File.file? navi_path
221
- rescue Errno::ESRCH
222
- # process exited normally
224
+ # Process.kill('QUIT', File.read(navi_path).to_i)
225
+ %x(kill -9 #{naviPid}) if naviPid
223
226
  rescue
224
- ensure
225
- FileUtils.rm_f navi_path
227
+ @logger.debug "Could not stop navi ai." unless @logger.nil?
226
228
  end
227
229
  end
228
230
 
@@ -34,7 +34,7 @@ module NaviClientInstaller
34
34
  def validate_email(email, pass)
35
35
  # need to remove this hardcoded code
36
36
  begin
37
- HTTParty.post("https://signin.navihq.com/oauth/token",
37
+ HTTParty.post(NaviClientInstaller::Settings::SSO_URL + "/oauth/token",
38
38
  body: {
39
39
  email: email, # get from sso_web application
40
40
  password: pass,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navilocal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Msanjib