navilocal 1.0.8 → 1.0.9

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: a20947b2bd4ecfd18dce0f3ac9a0c01fb8e13563b4a0c5d075ddf1aa04bbf2b6
4
- data.tar.gz: a137c27598d2282309bc5ddbe5d3e0d451ae76e96046dd843c5a176e03427242
3
+ metadata.gz: 223602614811ebf611613e5443045e790288bae8de501b2b711470e04d340715
4
+ data.tar.gz: '0096e6ce6bde4b267a643159c9b7bf1c946f12b34084c2f08ed424f41625a71f'
5
5
  SHA512:
6
- metadata.gz: 45a09a0e3ae7d106fd533e4395fd4fb8bdb8c332b86f55dd8c8eecec7edb19afd7672cfc974f64345ca9d788488d6fb05b796fbef6aec4547f36ca56a78cb207
7
- data.tar.gz: 54c1a1185942ee28d3e727c73164f3300b71ebd27c2ed9573683b57fa4ee0857b58cf3ee3f32a615f7a013c897caf75ae2a09ffe2e0f20e5103e465465a28d99
6
+ metadata.gz: 3159051407ce0afa9a42a00568fb4bff3520024cc96301c56ffc661e1737ac926dbdbb5e77539e666ca7477ba67d40a8a1941836e789610230114a42753707a6
7
+ data.tar.gz: b2900d824e9e50e64f8f7452a73d5c06d9da2b7dffc0d814f54547f1426701ed5e8bde3a93acd8360d17f47b7fff3aba360de8146ea3b0695973c3a55e34f18a
@@ -3,19 +3,12 @@ require 'json'
3
3
 
4
4
  module NaviClientInstaller
5
5
  class Settings
6
- PROPERTIES = [:provider, :username, :password, :agreement, :location, :creation_datetime, :last_modified, :download_path, :install, :hash, :client_log_file, :common_words_file, :wikipedia_topic_file, :ai_log_file, :logout].freeze
6
+ PROPERTIES = [:provider, :username, :password, :agreement, :location, :creation_datetime, :last_modified, :download_path, :install, :hash, :client_log_file, :common_words_file, :wikipedia_topic_file, :ai_log_file, :logout, :env].freeze
7
7
 
8
8
  PRIORITIES = ['high', 'medium', 'normal', 'low'].freeze
9
9
 
10
10
  DEFAULT_STORAGE = File.expand_path File.join('~', '.navi')
11
11
 
12
- SSO_URL = "https://signin.navihq.com"
13
- # SSO_URL = "http://localhost:3008"
14
- # GENERATE_CSV_URL = "http://localhost:3020/v2/generate_csv_input"
15
- GENERATE_CSV_URL = "https://api2.navihq.com/v2/generate_csv_input"
16
-
17
-
18
-
19
12
  attr_accessor *PROPERTIES
20
13
 
21
14
  def initialize(options = {})
@@ -33,6 +33,9 @@ module NaviClientInstaller
33
33
  @settings.load_from_file_yaml(NaviClientInstaller::Settings::DEFAULT_STORAGE + '/config.yml')
34
34
  @settings.creation_datetime = Time.now.to_s if @settings.creation_datetime.nil?
35
35
 
36
+ @settings.env = "production" if @settings.env.nil?
37
+ load_env @settings.env
38
+
36
39
  @splash = NaviClientInstaller::SplashWindow.new @settings
37
40
  @application = application
38
41
  main_stack.add_named(@splash.window_ui, "splash")
@@ -44,6 +47,13 @@ module NaviClientInstaller
44
47
  apply_css content_box, css_provider
45
48
  end
46
49
 
50
+ def load_env env = 'production'
51
+ application_root_path = File.expand_path('../../../', __dir__)
52
+ envs = YAML.load_file(File.join(application_root_path, 'resources', 'texts', 'env.yml'))[env]
53
+ ENV['env'] = env
54
+ envs.each {|k,v| ENV[k] = v }
55
+ end
56
+
47
57
  def initiate_splash
48
58
  bbox_navigation.set_visible false
49
59
  main_stack.set_visible_child(@splash.window_ui)
@@ -23,6 +23,7 @@ module NaviClientInstaller
23
23
  @refresh_btn = builder.get_object("process_refresh_btn")
24
24
  @email_display = builder.get_object("email_label_holder")
25
25
  @settings = settings
26
+ stop_naviai
26
27
 
27
28
  @email_display.label = settings&.username if settings&.username
28
29
 
@@ -69,6 +70,11 @@ module NaviClientInstaller
69
70
  def set_logout_action logout_control, application
70
71
  @action_logout = Gio::SimpleAction.new("logout")
71
72
  @action_logout.signal_connect("activate") do |_action, parameter|
73
+ @settings.logout = true
74
+ @settings.username = nil
75
+ @settings.password = nil
76
+ @settings.hash = nil
77
+ @settings.save_settings
72
78
  terminate_worker_thread
73
79
  logout_control.call
74
80
  @action_logout.set_enabled false
@@ -122,11 +128,7 @@ module NaviClientInstaller
122
128
 
123
129
  def start_fetching
124
130
 
125
- env = "development"
126
- sso_web_url = NaviClientInstaller::Settings::SSO_URL
127
- gen_csv_url = NaviClientInstaller::Settings::GENERATE_CSV_URL
128
-
129
- @client = NaviClient::Local.new(sso_web_url, "local", gen_csv_url, true, env)
131
+ @client = NaviClient::Local.new
130
132
  @client.set_token "Token: #{@token}##{@settings.username}"
131
133
  @logger = CustomLogger.new @log_display.buffer, @iter_log, @client.logger
132
134
  @client.override_logger @logger
@@ -166,20 +168,22 @@ module NaviClientInstaller
166
168
  downloaded = [downloaded, total].min
167
169
 
168
170
  @email_indicator.label = "#{downloaded}/#{total}"
169
- @client.logToLoggly({event:"EMAIL_SYNC_STARTED", env: env, storage: "local", email: @settings.username, total_email: total, already_downloaded: downloaded})
171
+ @client.logToLoggly({event:"EMAIL_SYNC_STARTED", env: ENV['env'], storage: "local", email: @settings.username, total_email: total, already_downloaded: downloaded})
170
172
 
171
173
  # start_naviai
172
174
  @notifier.label = "Checking for previous failures.."
173
-
175
+ @logger.debug "Parsing previously fetched emails"
174
176
  start_naviai
175
177
  new_emails = @client.parse_prev_failed_emails
176
- stop_naviai
178
+ @logger.debug "Complete. OK..."
179
+ # stop_naviai
177
180
  @notifier.label = "Fetching emails..."
181
+ stamp = (Time.now.to_f * 1000).to_s
178
182
  @client.retrieve_emails(@imap, ['ALL'], folder) do |mail, index, isLast, id|
179
183
 
180
184
  @logger.debug "processing email##{index + 1} with id #{mail.__id__.to_s} and uuid #{id}"
181
185
 
182
- filenames << @client.process_email(mail, id)
186
+ filenames << @client.process_email(mail, id, stamp)
183
187
  downloaded+=1
184
188
  downloaded = [downloaded, total].min
185
189
  @email_indicator.label = "#{downloaded}/#{total}"
@@ -188,20 +192,21 @@ module NaviClientInstaller
188
192
 
189
193
  if filenames.size == 50 || isLast
190
194
  sendEmailCompletedEvent = !sendEmailCompletedEvent
195
+ stamp = (Time.now.to_f * 1000).to_s
191
196
 
192
197
  @logger.debug "Sending Bulk Request for #{isLast ? filenames.size : 50} emails to Navi AI."
193
198
  @notifier.label = "Parsing the emails..."
194
199
 
195
200
  start_naviai
196
- @client.send_request(filenames)
197
- stop_naviai
201
+ @client.send_request(filenames, stamp)
202
+ # stop_naviai
198
203
 
199
204
  @logger.debug "Complete Ok... continue email sync"
200
205
  @notifier.label = "Fetching emails..."
201
206
  # verify
202
207
  filenames = []
203
208
  if sendEmailCompletedEvent && !isLast
204
- @client.logToLoggly({event:"EMAIL_SYNC_IN_PROGRESS", env: env, storage: "local", email: @settings.username, emailCount: index + 1})
209
+ @client.logToLoggly({event:"EMAIL_SYNC_IN_PROGRESS", env: ENV['env'], storage: "local", email: @settings.username, emailCount: index + 1})
205
210
  # exit
206
211
  elsif isLast
207
212
 
@@ -209,7 +214,7 @@ module NaviClientInstaller
209
214
  totalTimeInSecs = (dateEnded - dateStarted) * 24 * 60 * 60
210
215
  new_emails = true
211
216
 
212
- @client.logToLoggly({event:"EMAIL_SYNC_FINISHED", env: env, storage: "local", email: @settings.username, emailCount: index + 1, time_elapsed: totalTimeInSecs.to_f.round(2), total_email: total, already_downloaded: downloaded})
217
+ @client.logToLoggly({event:"EMAIL_SYNC_FINISHED", env: ENV['env'], storage: "local", email: @settings.username, emailCount: index + 1, time_elapsed: totalTimeInSecs.to_f.round(2), total_email: total, already_downloaded: downloaded})
213
218
  @logger.debug "#{index + 1} emails from the #{folder} has been downloaded. OK"
214
219
  @logger.debug "started: #{dateStarted.to_s} , ended: #{dateEnded.to_s}, Total time: #{totalTimeInSecs.to_f.round(2)} secs"
215
220
  end
@@ -244,7 +249,7 @@ module NaviClientInstaller
244
249
  @notifier.label = "Parsing the emails..."
245
250
  start_naviai
246
251
  else
247
- stop_naviai
252
+ # stop_naviai
248
253
  @logger.debug "Waiting new mails (IDLE loop)..."
249
254
  @notifier.label = "Waiting for the new emails.."
250
255
  end
@@ -273,10 +278,32 @@ module NaviClientInstaller
273
278
  end
274
279
 
275
280
  def start_naviai
276
- stop_naviai
277
- navi_path = NaviClientInstaller::Settings::DEFAULT_STORAGE
278
- system("#{navi_path}/bin/naviai &")
279
- sleep 1
281
+
282
+ if(!isNaviAiUp)
283
+ # stop_naviai
284
+ navi_path = NaviClientInstaller::Settings::DEFAULT_STORAGE
285
+ system("#{navi_path}/bin/naviai &")
286
+
287
+ up = false
288
+ while ! up
289
+ up = isNaviAiUp
290
+ sleep 5
291
+ end
292
+
293
+ end
294
+
295
+
296
+ end
297
+
298
+ def isNaviAiUp
299
+ begin
300
+ # Process.kill('QUIT', File.read(navi_path).to_i)
301
+ up = %x(lsof -i tcp:9090 | grep naviai | awk {'print $2'})
302
+
303
+ return ! up.to_s.empty?
304
+ rescue
305
+ return false
306
+ end
280
307
  end
281
308
 
282
309
  def stop_naviai
@@ -285,7 +312,7 @@ module NaviClientInstaller
285
312
  # Process.kill('QUIT', File.read(navi_path).to_i)
286
313
  %x(lsof -i tcp:9090 | grep naviai | awk {'print $2'} | xargs kill -9)
287
314
  rescue
288
- @logger.debug "Could not stop navi ai." unless @logger.nil?
315
+ @logger.debug "Could not stop navi server." unless @logger.nil?
289
316
  end
290
317
  end
291
318
 
@@ -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(NaviClientInstaller::Settings::SSO_URL + "/oauth/token",
37
+ HTTParty.post(ENV['api_url'] + "/oauth/token",
38
38
  body: {
39
39
  email: email, # get from sso_web application
40
40
  password: pass,
@@ -0,0 +1,11 @@
1
+ development:
2
+ api_url: http://localhost:3020/
3
+ parser_url: http://localhost:9090
4
+
5
+ staging:
6
+ api_url: http://localhost:3020
7
+ parser_url: http://34.214.134.104:9090
8
+
9
+ production:
10
+ api_url: https://signin.navihq.com
11
+ parser_url: http://localhost:9090
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: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Msanjib
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.4.3
47
+ version: 1.4.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.4.3
54
+ version: 1.4.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: httparty
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +87,7 @@ files:
87
87
  - application/ui/navi/splash.rb
88
88
  - bin/navilocal
89
89
  - gresource.bin
90
+ - resources/texts/env.yml
90
91
  homepage: http://rubygems.org/gems/navilocal
91
92
  licenses:
92
93
  - NAVI