zuora_connect 1.7.88 → 1.7.710
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 +5 -5
- data/app/controllers/zuora_connect/api/v1/app_instance_controller.rb +0 -13
- data/app/controllers/zuora_connect/static_controller.rb +6 -19
- data/app/models/zuora_connect/app_instance_base.rb +60 -122
- data/app/models/zuora_connect/telegraf.rb +7 -11
- data/config/initializers/redis.rb +2 -2
- data/config/initializers/resque.rb +1 -10
- data/config/routes.rb +0 -1
- data/db/migrate/20100718151733_create_connect_app_instances.rb +1 -1
- data/db/migrate/20101024162319_add_tokens_to_app_instance.rb +1 -1
- data/db/migrate/20101024220705_add_token_to_app_instance.rb +1 -1
- data/db/migrate/20110131211919_add_sessions_table.rb +1 -1
- data/db/migrate/20110411200303_add_expiration_to_app_instance.rb +1 -1
- data/db/migrate/20110413191512_add_new_api_token.rb +1 -1
- data/db/migrate/20110503003602_add_catalog_data_to_app_instance.rb +1 -1
- data/db/migrate/20110503003603_add_catalog_mappings_to_app_instance.rb +1 -1
- data/db/migrate/20110503003604_catalog_default.rb +1 -1
- data/db/migrate/20180301052853_add_catalog_attempted_at.rb +1 -1
- data/db/migrate/20181206162339_add_fields_to_instance.rb +1 -1
- data/lib/metrics/net.rb +2 -2
- data/lib/middleware/metrics_middleware.rb +2 -5
- data/lib/resque/plugins/custom_logger.rb +31 -14
- data/lib/zuora_connect/configuration.rb +1 -0
- data/lib/zuora_connect/controllers/helpers.rb +16 -15
- data/lib/zuora_connect/engine.rb +1 -2
- data/lib/zuora_connect/railtie.rb +15 -21
- data/lib/zuora_connect/version.rb +1 -1
- data/lib/zuora_connect.rb +0 -109
- metadata +45 -74
- data/lib/logging/connect_formatter.rb +0 -39
- data/lib/middleware/request_id_middleware.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e96d28bc77c7265cd2ba00b34fda0f2c278561b2
|
4
|
+
data.tar.gz: 57b1a0d66be1148960ecf5322ea5710ee9d55d62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 041ff1a6cd3eb7e5716b069f5b60bb78f07a976d6000876c20adbf623aaad5f150d78ef19c7ec0d1a3e53c865c0e79579f53cbafaf06c7d92e00eaf822523643
|
7
|
+
data.tar.gz: 370c8b43ee1fc8a6c7a58a6b64c61430ff428478d14ffc894bd90738dde85517a37204de7a8f5d9157870b8bb24748e6e9af4bfe8dcbe6e8aa8bd23bafe532d7
|
@@ -41,18 +41,5 @@ module ZuoraConnect
|
|
41
41
|
|
42
42
|
end
|
43
43
|
|
44
|
-
def cache_bust
|
45
|
-
if defined?(Redis.current)
|
46
|
-
Redis.current.del("AppInstance:#{@appinstance.id}")
|
47
|
-
respond_to do |format|
|
48
|
-
format.json {render json: {}, status: :ok}
|
49
|
-
end
|
50
|
-
else
|
51
|
-
respond_to do |format|
|
52
|
-
format.json {render json: {}, status: :bad_request}
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
44
|
end
|
58
45
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
class StaticController < ApplicationController
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
before_filter :authenticate_connect_app_request, :except => [:metrics, :health, :session_error, :invalid_app_instance_error, :initialize_app]
|
4
|
+
before_filter :clear_connect_app_session, :only => [:metrics, :health, :session_error, :invalid_app_instance_error, :initialize_app]
|
5
|
+
after_filter :persist_connect_app_session, :except => [:metrics, :health, :session_error, :invalid_app_instance_error, :initialize_app]
|
6
6
|
|
7
|
-
|
7
|
+
skip_before_filter :verify_authenticity_token, :only => [:initialize_app]
|
8
8
|
|
9
9
|
def session_error
|
10
10
|
respond_to do |format|
|
@@ -26,19 +26,6 @@ module ZuoraConnect
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def health
|
29
|
-
if params[:error].present?
|
30
|
-
begin
|
31
|
-
raise ZuoraConnect::Exceptions::Error.new('This is an error')
|
32
|
-
rescue => ex
|
33
|
-
case params[:error]
|
34
|
-
when 'Log'
|
35
|
-
Rails.logger.error(ex)
|
36
|
-
when 'Exception'
|
37
|
-
raise
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
29
|
render json: {
|
43
30
|
message: "Alive",
|
44
31
|
status: 200
|
@@ -55,8 +42,8 @@ module ZuoraConnect
|
|
55
42
|
rescue
|
56
43
|
render json: {
|
57
44
|
message: "Failure initializing app instance",
|
58
|
-
status:
|
59
|
-
}, status:
|
45
|
+
status: 400
|
46
|
+
}, status: 400
|
60
47
|
end
|
61
48
|
end
|
62
49
|
|
@@ -4,7 +4,6 @@ module ZuoraConnect
|
|
4
4
|
default_scope {select(ZuoraConnect::AppInstance.column_names.delete_if {|x| ["catalog_mapping", "catalog"].include?(x) }) }
|
5
5
|
after_initialize :init
|
6
6
|
after_create :initialize_redis_placeholder
|
7
|
-
before_destroy :prune_data
|
8
7
|
|
9
8
|
self.table_name = "zuora_connect_app_instances"
|
10
9
|
attr_accessor :options, :mode, :logins, :task_data, :last_refresh, :username, :password, :s3_client, :api_version, :drop_message, :new_session_message, :connect_user, :logitems
|
@@ -16,7 +15,6 @@ module ZuoraConnect
|
|
16
15
|
BLANK_OBJECT_ID_LOOKUP = 'BlankValueSupplied'
|
17
16
|
HOLDING_PATTERN_SLEEP = 5.seconds
|
18
17
|
CONNECT_COMMUNICATION_SLEEP= 5.seconds
|
19
|
-
IGNORED_LOCALS = ['fr', 'ja', 'sp']
|
20
18
|
|
21
19
|
def init
|
22
20
|
self.connect_user = 'Nobody'
|
@@ -28,9 +26,9 @@ module ZuoraConnect
|
|
28
26
|
self.attr_builder("timezone", ZuoraConnect.configuration.default_time_zone)
|
29
27
|
self.attr_builder("locale", ZuoraConnect.configuration.default_locale)
|
30
28
|
PaperTrail.whodunnit = "Backend" if defined?(PaperTrail)
|
31
|
-
if defined?(ElasticAPM)
|
29
|
+
if defined?(ElasticAPM)
|
32
30
|
ElasticAPM.set_user("Backend")
|
33
|
-
ElasticAPM.set_tag(:app_instance, self.id)
|
31
|
+
ElasticAPM.set_tag(:app_instance, self.id)
|
34
32
|
end
|
35
33
|
|
36
34
|
if INSTANCE_REFRESH_WINDOW > INSTANCE_REDIS_CACHE_PERIOD
|
@@ -41,7 +39,6 @@ module ZuoraConnect
|
|
41
39
|
|
42
40
|
def initialize_redis_placeholder
|
43
41
|
if defined?(Redis.current)
|
44
|
-
Redis.current.zrem("AppInstance:Deleted", id)
|
45
42
|
Redis.current.zadd("APILimits", 9999999999, "placeholder")
|
46
43
|
Redis.current.zadd("InstanceRefreshing", 9999999999, "placeholder")
|
47
44
|
end
|
@@ -50,39 +47,18 @@ module ZuoraConnect
|
|
50
47
|
end
|
51
48
|
end
|
52
49
|
|
53
|
-
def prune_data(id: self.id)
|
54
|
-
if defined?(Redis.current)
|
55
|
-
Redis.current.zadd("AppInstance:Deleted", Time.now.to_i, id)
|
56
|
-
Redis.current.del("AppInstance:#{id}")
|
57
|
-
Redis.current.zrem("APILimits", id)
|
58
|
-
Redis.current.zrem("InstanceRefreshing", id)
|
59
|
-
end
|
60
|
-
if defined?(Resque.redis)
|
61
|
-
Resque.redis.zrem("PauseQueue", id)
|
62
|
-
end
|
63
|
-
return true
|
64
|
-
end
|
65
|
-
|
66
50
|
def apartment_switch(method = nil, migrate = false)
|
67
|
-
|
68
|
-
|
51
|
+
begin
|
52
|
+
Apartment::Tenant.switch!(self.id) if self.persisted?
|
53
|
+
rescue Apartment::TenantNotFound => ex
|
69
54
|
begin
|
70
|
-
Apartment::Tenant.
|
71
|
-
rescue Apartment::
|
72
|
-
sleep(2)
|
73
|
-
begin
|
74
|
-
Apartment::Tenant.create(self.id.to_s)
|
75
|
-
rescue Apartment::TenantExists => ex
|
76
|
-
end
|
77
|
-
if (switch_count += 1) < 2
|
78
|
-
retry
|
79
|
-
else
|
80
|
-
raise
|
81
|
-
end
|
82
|
-
end
|
83
|
-
if migrate && ActiveRecord::Migrator.needs_migration?
|
84
|
-
Apartment::Migrator.migrate(self.id)
|
55
|
+
Apartment::Tenant.create(self.id.to_s)
|
56
|
+
rescue Apartment::TenantExists => ex
|
85
57
|
end
|
58
|
+
retry
|
59
|
+
end
|
60
|
+
if migrate && ActiveRecord::Migrator.needs_migration?
|
61
|
+
Apartment::Migrator.migrate(self.id)
|
86
62
|
end
|
87
63
|
Thread.current[:appinstance] = self
|
88
64
|
end
|
@@ -94,7 +70,7 @@ module ZuoraConnect
|
|
94
70
|
self.last_refresh = session["#{self.id}::last_refresh"]
|
95
71
|
self.connect_user = session["#{self.id}::user::email"] if session["#{self.id}::user::email"].present?
|
96
72
|
PaperTrail.whodunnit = self.connect_user if defined?(PaperTrail)
|
97
|
-
ElasticAPM.set_user(self.connect_user) if defined?(ElasticAPM)
|
73
|
+
ElasticAPM.set_user(self.connect_user) if defined?(ElasticAPM)
|
98
74
|
recoverable_session = false
|
99
75
|
|
100
76
|
## DEV MODE TASK DATA MOCKUP
|
@@ -121,26 +97,26 @@ module ZuoraConnect
|
|
121
97
|
|
122
98
|
if session.empty?
|
123
99
|
self.new_session_message = "REFRESHING - Session Empty"
|
124
|
-
|
100
|
+
Rails.logger.add(log_level, self.new_session_message)
|
125
101
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
126
102
|
self.refresh(session: session)
|
127
103
|
|
128
104
|
elsif (self.id != session["appInstance"].to_i)
|
129
105
|
self.new_session_message = "REFRESHING - AppInstance ID(#{self.id}) does not match session id(#{session["appInstance"].to_i})"
|
130
|
-
|
106
|
+
Rails.logger.add(log_level, self.new_session_message)
|
131
107
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
132
108
|
self.refresh(session: session)
|
133
109
|
|
134
110
|
elsif session["#{self.id}::task_data"].blank?
|
135
111
|
self.new_session_message = "REFRESHING - Task Data Blank"
|
136
|
-
|
112
|
+
Rails.logger.add(log_level, self.new_session_message)
|
137
113
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
138
114
|
self.refresh(session: session)
|
139
115
|
|
140
116
|
elsif session["#{self.id}::last_refresh"].blank?
|
141
117
|
self.new_session_message = "REFRESHING - No Time on Cookie"
|
142
118
|
recoverable_session = true
|
143
|
-
|
119
|
+
Rails.logger.add(log_level, self.new_session_message)
|
144
120
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
145
121
|
self.refresh(session: session)
|
146
122
|
|
@@ -148,7 +124,7 @@ module ZuoraConnect
|
|
148
124
|
elsif (session["#{self.id}::last_refresh"].to_i < INSTANCE_REFRESH_WINDOW.ago.to_i) && self.mark_for_refresh
|
149
125
|
self.new_session_message = "REFRESHING - Session Old by #{time_expire.abs} second"
|
150
126
|
recoverable_session = true
|
151
|
-
|
127
|
+
Rails.logger.add(log_level, self.new_session_message)
|
152
128
|
self.refresh(session: session)
|
153
129
|
|
154
130
|
else
|
@@ -157,22 +133,22 @@ module ZuoraConnect
|
|
157
133
|
else
|
158
134
|
self.new_session_message = "REBUILDING - Expires in #{time_expire} seconds"
|
159
135
|
end
|
160
|
-
|
136
|
+
Rails.logger.add(log_level, self.new_session_message)
|
161
137
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
162
138
|
end
|
163
|
-
end
|
139
|
+
end
|
164
140
|
return self
|
165
141
|
rescue ZuoraConnect::Exceptions::HoldingPattern => ex
|
166
142
|
while self.marked_for_refresh?
|
167
|
-
|
143
|
+
Rails.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'")
|
168
144
|
sleep(HOLDING_PATTERN_SLEEP)
|
169
145
|
end
|
170
146
|
self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
|
171
147
|
session = self.data_lookup(session: session)
|
172
148
|
retry
|
173
|
-
rescue => ex
|
149
|
+
rescue => ex
|
174
150
|
if recoverable_session
|
175
|
-
|
151
|
+
Rails.logger.error("REBUILDING - Using backup expired cache")
|
176
152
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
177
153
|
return self
|
178
154
|
else
|
@@ -182,17 +158,17 @@ module ZuoraConnect
|
|
182
158
|
begin
|
183
159
|
I18n.locale = self.locale
|
184
160
|
rescue I18n::InvalidLocale => ex
|
185
|
-
|
161
|
+
Rails.logger.debug("Invalid Locale: #{ex.message}")
|
186
162
|
end
|
187
163
|
Time.zone = self.timezone
|
188
164
|
tenants = self.task_data.dig('tenant_ids') || []
|
189
165
|
organizations = self.task_data.dig('organizations') || []
|
190
|
-
if defined?(ElasticAPM)
|
166
|
+
if defined?(ElasticAPM)
|
191
167
|
ElasticAPM.set_tag(:tenant_id, tenants.first)
|
192
168
|
ElasticAPM.set_tag(:organization, organizations.first)
|
193
169
|
end
|
194
170
|
self.logitem(item: {tenant_ids: tenants, organization: organizations})
|
195
|
-
self.update_column(:name, self.task_data.dig('name')) if ZuoraConnect::AppInstance.column_names.include?('name') && self.task_data.dig('name') != self.name
|
171
|
+
self.update_column(:name, self.task_data.dig('name')) if ZuoraConnect::AppInstance.column_names.include?('name') && self.task_data.dig('name') != self.name
|
196
172
|
end
|
197
173
|
|
198
174
|
def refresh(session: {}, session_fallback: false)
|
@@ -201,34 +177,33 @@ module ZuoraConnect
|
|
201
177
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
202
178
|
response_time = Time.now - start
|
203
179
|
|
204
|
-
|
180
|
+
Rails.logger.debug("[#{self.id}] REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}")
|
205
181
|
if response.code == 200
|
206
182
|
self.build_task(task_data: JSON.parse(response.body), session: session)
|
207
183
|
self.last_refresh = Time.now.to_i
|
208
184
|
self.cache_app_instance
|
209
185
|
self.reset_mark_for_refresh
|
210
186
|
else
|
187
|
+
Rails.logger.fatal("[#{self.id}] REFRESH TASK - Failed Code #{response.code}")
|
211
188
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
212
189
|
end
|
213
190
|
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
214
191
|
if (refresh_count += 1) < 3
|
215
|
-
|
192
|
+
Rails.logger.info("[#{self.id}] REFRESH TASK - #{ex.class} Retrying(#{refresh_count})")
|
216
193
|
retry
|
217
194
|
else
|
218
|
-
|
195
|
+
Rails.logger.fatal("[#{self.id}] REFRESH TASK - #{ex.class} Failed #{refresh_count}x")
|
219
196
|
raise
|
220
197
|
end
|
221
198
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
222
199
|
if (refresh_count += 1) < 3
|
200
|
+
Rails.logger.info("[#{self.id}] REFRESH TASK - Failed Retrying(#{refresh_count})")
|
223
201
|
if ex.code == 401
|
224
|
-
ZuoraConnect.logger.info("[#{self.id}] REFRESH TASK - Failed #{ex.code} - Retrying(#{refresh_count})")
|
225
202
|
self.refresh_oauth
|
226
|
-
else
|
227
|
-
ZuoraConnect.logger.warn("[#{self.id}] REFRESH TASK - Failed #{ex.code} - Retrying(#{refresh_count})")
|
228
203
|
end
|
229
204
|
retry
|
230
205
|
else
|
231
|
-
|
206
|
+
Rails.logger.fatal("[#{self.id}] REFRESH TASK - Failed #{refresh_count}x")
|
232
207
|
raise
|
233
208
|
end
|
234
209
|
end
|
@@ -245,45 +220,10 @@ module ZuoraConnect
|
|
245
220
|
def self.write_to_telegraf(*args)
|
246
221
|
if ZuoraConnect.configuration.enable_metrics
|
247
222
|
@@telegraf_host = ZuoraConnect::Telegraf.new() if @@telegraf_host == nil
|
248
|
-
unicorn_stats = self.unicorn_listener_stats() if defined?(Unicorn) && Unicorn.respond_to?(:listener_names)
|
249
|
-
@@telegraf_host.write(direction: 'Raindrops', tags: {}, values: unicorn_stats) unless unicorn_stats.blank?
|
250
223
|
return @@telegraf_host.write(*args)
|
251
224
|
end
|
252
225
|
end
|
253
226
|
|
254
|
-
def self.unicorn_listener_stats ()
|
255
|
-
stats_hash = {}
|
256
|
-
stats_hash["total_active"] = 0
|
257
|
-
stats_hash["total_queued"] = 0
|
258
|
-
|
259
|
-
begin
|
260
|
-
tmp = Unicorn.listener_names
|
261
|
-
unix = tmp.grep(%r{\A/})
|
262
|
-
tcp = tmp.grep(/\A.+:\d+\z/)
|
263
|
-
tcp = nil if tcp.empty?
|
264
|
-
unix = nil if unix.empty?
|
265
|
-
|
266
|
-
|
267
|
-
Raindrops::Linux.tcp_listener_stats(tcp).each do |addr,stats|
|
268
|
-
stats_hash["active_#{addr}"] = stats.active
|
269
|
-
stats_hash["queued_#{addr}"] = stats.queued
|
270
|
-
stats_hash["total_active"] = stats.active + stats_hash["total_active"]
|
271
|
-
stats_hash["total_queued"] = stats.queued + stats_hash["total_queued"]
|
272
|
-
end if tcp
|
273
|
-
|
274
|
-
Raindrops::Linux.unix_listener_stats(unix).each do |addr,stats|
|
275
|
-
stats_hash["active_#{addr}"] = stats.active
|
276
|
-
stats_hash["queued_#{addr}"] = stats.queued
|
277
|
-
stats_hash["total_active"] = stats.active + stats_hash["total_active"]
|
278
|
-
stats_hash["total_queued"] = stats.queued + stats_hash["total_queued"]
|
279
|
-
end if unix
|
280
|
-
rescue IOError => ex
|
281
|
-
rescue => ex
|
282
|
-
ZuoraConnect.logger.error(ex)
|
283
|
-
end
|
284
|
-
return stats_hash
|
285
|
-
end
|
286
|
-
|
287
227
|
def self.get_metrics(type)
|
288
228
|
@data = {}
|
289
229
|
|
@@ -338,7 +278,7 @@ module ZuoraConnect
|
|
338
278
|
else
|
339
279
|
tmp.client.current_session = session["#{self.id}::#{k}:current_session"] if session["#{self.id}::#{k}:current_session"]
|
340
280
|
tmp.client.bearer_token = session["#{self.id}::#{k}:bearer_token"] if session["#{self.id}::#{k}:bearer_token"] && tmp.client.respond_to?(:bearer_token) ## need incase session id goes from basic to aouth in same redis store
|
341
|
-
tmp.client.oauth_session_expires_at = session["#{self.id}::#{k}:oauth_session_expires_at"] if session["#{self.id}::#{k}:oauth_session_expires_at"] && tmp.client.respond_to?(:oauth_session_expires_at)
|
281
|
+
tmp.client.oauth_session_expires_at = session["#{self.id}::#{k}:oauth_session_expires_at"] if session["#{self.id}::#{k}:oauth_session_expires_at"] && tmp.client.respond_to?(:oauth_session_expires_at)
|
342
282
|
end
|
343
283
|
end
|
344
284
|
self.logins[k] = tmp
|
@@ -353,11 +293,8 @@ module ZuoraConnect
|
|
353
293
|
end
|
354
294
|
end
|
355
295
|
rescue => ex
|
356
|
-
|
357
|
-
if session.present?
|
358
|
-
ZuoraConnect.logger.error("Task Session: #{session.to_h}") if session.methods.include?(:to_h)
|
359
|
-
ZuoraConnect.logger.error("Task Session: #{session.to_hash}") if session.methods.include?(:to_hash)
|
360
|
-
end
|
296
|
+
Rails.logger.error("Task Data: #{task_data}") if task_data.present?
|
297
|
+
Rails.logger.error("Task Session: #{session.to_h}") if session.present?
|
361
298
|
raise
|
362
299
|
end
|
363
300
|
|
@@ -433,7 +370,7 @@ module ZuoraConnect
|
|
433
370
|
def check_oauth_state(method)
|
434
371
|
#Refresh token if already expired
|
435
372
|
if self.oauth_expired?
|
436
|
-
|
373
|
+
Rails.logger.debug("[#{self.id}] Before '#{method}' method, Oauth expired")
|
437
374
|
self.refresh_oauth
|
438
375
|
end
|
439
376
|
end
|
@@ -452,7 +389,7 @@ module ZuoraConnect
|
|
452
389
|
}
|
453
390
|
response = HTTParty.post("#{ZuoraConnect.configuration.url}/oauth/token",:body => params)
|
454
391
|
response_time = Time.now - start
|
455
|
-
|
392
|
+
Rails.logger.info("[#{self.id}] REFRESH OAUTH - In #{response_time.round(2).to_s}")
|
456
393
|
|
457
394
|
if response.code == 200
|
458
395
|
response_body = JSON.parse(response.body)
|
@@ -462,14 +399,15 @@ module ZuoraConnect
|
|
462
399
|
self.oauth_expires_at = Time.at(response_body["created_at"].to_i) + response_body["expires_in"].seconds
|
463
400
|
self.save(:validate => false)
|
464
401
|
else
|
465
|
-
|
402
|
+
Rails.logger.fatal("[#{self.id}] REFRESH OAUTH - Failed Code #{response.code}")
|
403
|
+
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Refreshing Access Token", response.body, response.code)
|
466
404
|
end
|
467
405
|
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
468
406
|
if (refresh_oauth_count += 1) < 3
|
469
|
-
|
407
|
+
Rails.logger.info("[#{self.id}] REFRESH OAUTH - #{ex.class} Retrying(#{refresh_oauth_count})")
|
470
408
|
retry
|
471
409
|
else
|
472
|
-
|
410
|
+
Rails.logger.fatal("[#{self.id}] REFRESH OAUTH - #{ex.class} Failed #{refresh_oauth_count}x")
|
473
411
|
raise
|
474
412
|
end
|
475
413
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
@@ -480,10 +418,10 @@ module ZuoraConnect
|
|
480
418
|
return if !self.oauth_expired?
|
481
419
|
|
482
420
|
if (refresh_oauth_count += 1) < 3
|
483
|
-
|
421
|
+
Rails.logger.info("[#{self.id}] REFRESH OAUTH - Failed Retrying(#{refresh_oauth_count})")
|
484
422
|
retry
|
485
423
|
else
|
486
|
-
|
424
|
+
Rails.logger.fatal("[#{self.id}] REFRESH OAUTH - Failed #{refresh_oauth_count}x")
|
487
425
|
raise
|
488
426
|
end
|
489
427
|
end
|
@@ -533,10 +471,10 @@ module ZuoraConnect
|
|
533
471
|
end
|
534
472
|
end
|
535
473
|
if cached_instance.blank?
|
536
|
-
|
474
|
+
Rails.logger.debug("[#{self.id}] Cached AppInstance Missing")
|
537
475
|
return session
|
538
476
|
else
|
539
|
-
|
477
|
+
Rails.logger.debug("[#{self.id}] Cached AppInstance Found")
|
540
478
|
return decrypt_data(data: cached_instance, rescue_return: session).merge(session)
|
541
479
|
end
|
542
480
|
else
|
@@ -548,7 +486,7 @@ module ZuoraConnect
|
|
548
486
|
if defined?(Redis.current)
|
549
487
|
#Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
|
550
488
|
if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
|
551
|
-
|
489
|
+
Rails.logger.debug("[#{self.id}] Caching AppInstance")
|
552
490
|
Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
|
553
491
|
end
|
554
492
|
end
|
@@ -600,16 +538,16 @@ module ZuoraConnect
|
|
600
538
|
def decrypt_data(data: nil, rescue_return: nil, log_fatal: true)
|
601
539
|
return data if data.blank?
|
602
540
|
if Rails.env == 'development'
|
603
|
-
begin
|
541
|
+
begin
|
604
542
|
return JSON.parse(data)
|
605
543
|
rescue JSON::ParserError => ex
|
606
544
|
return data
|
607
545
|
end
|
608
546
|
else
|
609
|
-
begin
|
547
|
+
begin
|
610
548
|
return JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
|
611
549
|
rescue ActiveSupport::MessageVerifier::InvalidSignature => ex
|
612
|
-
|
550
|
+
Rails.logger.add(Logger::FATAL, 'Error Decrypting') if log_fatal
|
613
551
|
return rescue_return
|
614
552
|
rescue JSON::ParserError => ex
|
615
553
|
return encryptor.decrypt_and_verify(CGI::unescape(data))
|
@@ -661,7 +599,7 @@ module ZuoraConnect
|
|
661
599
|
if paused_user == current_user || paused_user.blank?
|
662
600
|
Resque.redis.zrem("PauseQueue", "#{self.id}__#{paused_user}")
|
663
601
|
else
|
664
|
-
raise "Can only unpause for user #{paused_user}."
|
602
|
+
raise "Can only unpause for user #{paused_user}."
|
665
603
|
end
|
666
604
|
end
|
667
605
|
### END Resque Helping Methods ####
|
@@ -671,8 +609,8 @@ module ZuoraConnect
|
|
671
609
|
self.update_column(:catalog_update_attempt_at, Time.now.utc)
|
672
610
|
|
673
611
|
entity_reference = entity_id.blank? ? 'Default' : entity_id
|
674
|
-
|
675
|
-
|
612
|
+
Rails.logger.debug("Fetch Catalog")
|
613
|
+
Rails.logger.debug("Zuora Entity: #{entity_id.blank? ? 'default' : entity_id}")
|
676
614
|
|
677
615
|
login = zuora_login.client(entity_reference)
|
678
616
|
|
@@ -683,12 +621,12 @@ module ZuoraConnect
|
|
683
621
|
response = {'nextPage' => login.rest_endpoint("catalog/products?pageSize=#{page_size}")}
|
684
622
|
while !response["nextPage"].blank?
|
685
623
|
url = login.rest_endpoint(response["nextPage"].split('/v1/').last)
|
686
|
-
|
624
|
+
Rails.logger.debug("Fetch Catalog URL #{url}")
|
687
625
|
output_json, response = login.rest_call(:debug => false, :url => url, :errors => [ZuoraAPI::Exceptions::ZuoraAPISessionError], :timeout_retry => true)
|
688
|
-
|
626
|
+
Rails.logger.debug("Fetch Catalog Response Code #{response.code}")
|
689
627
|
|
690
628
|
if !output_json['success'] =~ (/(true|t|yes|y|1)$/i) || output_json['success'].class != TrueClass
|
691
|
-
|
629
|
+
Rails.logger.error("Fetch Catalog DATA #{output_json.to_json}")
|
692
630
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Error Getting Catalog: #{output_json}")
|
693
631
|
end
|
694
632
|
|
@@ -875,7 +813,7 @@ module ZuoraConnect
|
|
875
813
|
if cache
|
876
814
|
Redis.current.sadd("Catalog:#{self.id}:Keys", ["Catalog:#{self.id}:#{object_id}:Hierarchy", "Catalog:#{self.id}:#{object_id}:Children:#{child_objects}"])
|
877
815
|
Redis.current.set("Catalog:#{self.id}:#{object_id}:Hierarchy", encrypt_data(data: object_hierarchy))
|
878
|
-
Redis.current.set("Catalog:#{self.id}:#{object_id}:Children:#{child_objects}", encrypt_data(data: stub_catalog))
|
816
|
+
Redis.current.set("Catalog:#{self.id}:#{object_id}:Children:#{child_objects}", encrypt_data(data: stub_catalog))
|
879
817
|
else
|
880
818
|
Redis.current.sadd("Catalog:#{self.id}:Keys", ["Catalog:#{self.id}:#{object_id}:Hierarchy"])
|
881
819
|
Redis.current.set("Catalog:#{self.id}:#{object_id}:Hierarchy", encrypt_data(data: object_hierarchy))
|
@@ -914,7 +852,7 @@ module ZuoraConnect
|
|
914
852
|
self.update_functions
|
915
853
|
if index_table
|
916
854
|
ActiveRecord::Base.connection.execute('SELECT "shared_extensions".refresh_aggregate_table(\'%s\', \'%s\', %s, \'Index\');' % [aggregate_name, table_name, ActiveRecord::Base.connection.quote(where_clause)])
|
917
|
-
else
|
855
|
+
else
|
918
856
|
ActiveRecord::Base.connection.execute('SELECT "shared_extensions".refresh_aggregate_table(\'%s\', \'%s\', %s, \'NO\');' % [aggregate_name, table_name, ActiveRecord::Base.connection.quote(where_clause)])
|
919
857
|
end
|
920
858
|
end
|
@@ -978,9 +916,9 @@ module ZuoraConnect
|
|
978
916
|
|
979
917
|
def method_missing(method_sym, *arguments, &block)
|
980
918
|
if method_sym.to_s.include?("login")
|
981
|
-
|
982
|
-
|
983
|
-
|
919
|
+
Rails.logger.fatal("Method Missing #{method_sym}")
|
920
|
+
Rails.logger.fatal("Instance Data: #{self.task_data}")
|
921
|
+
Rails.logger.fatal("Instance Logins: #{self.logins}")
|
984
922
|
end
|
985
923
|
super
|
986
924
|
end
|
@@ -988,4 +926,4 @@ module ZuoraConnect
|
|
988
926
|
method_hook :refresh, :updateOption, :update_logins, :before => :check_oauth_state
|
989
927
|
method_hook :new_session, :refresh, :build_task, :after => :apartment_switch
|
990
928
|
end
|
991
|
-
end
|
929
|
+
end
|
@@ -12,14 +12,14 @@ module ZuoraConnect
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def connect
|
15
|
-
|
15
|
+
Rails.logger.debug(self.format_metric_log('Telegraf','Need new connection')) if ZuoraConnect.configuration.telegraf_debug
|
16
16
|
uri = URI.parse(ZuoraConnect.configuration.telegraf_endpoint)
|
17
17
|
self.host = UDPSocket.new.tap do |socket|
|
18
18
|
socket.connect uri.host, uri.port
|
19
19
|
end
|
20
20
|
rescue => ex
|
21
21
|
self.host = nil
|
22
|
-
|
22
|
+
Rails.logger.warn(self.format_metric_log('Telegraf', "Failed to connect: #{ex.class}"))
|
23
23
|
end
|
24
24
|
|
25
25
|
def write(direction: 'Unknown', tags: {}, values: {})
|
@@ -44,9 +44,9 @@ module ZuoraConnect
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
if ZuoraConnect.configuration.telegraf_debug
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
Rails.logger.debug(self.format_metric_log('Telegraf', tags.to_s))
|
48
|
+
Rails.logger.debug(self.format_metric_log('Telegraf', values.to_s))
|
49
|
+
Rails.logger.debug(self.format_metric_log('Telegraf', "Writing '#{direction.capitalize}': #{time.real.round(5)} ms"))
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -56,18 +56,14 @@ module ZuoraConnect
|
|
56
56
|
self.host.write InfluxDB::PointValue.new({series: series, tags: tags, values: values}).dump
|
57
57
|
rescue => ex
|
58
58
|
self.connect
|
59
|
-
|
59
|
+
Rails.logger.warn(self.format_metric_log('Telegraf',"Failed to write udp: #{ex.class}"))
|
60
60
|
end
|
61
61
|
|
62
62
|
def format_metric_log(message, dump = nil)
|
63
63
|
message_color, dump_color = "1;91", "0;1"
|
64
64
|
log_entry = " \e[#{message_color}m#{message}\e[0m "
|
65
65
|
log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
|
66
|
-
|
67
|
-
log_entry
|
68
|
-
else
|
69
|
-
[message, dump].compact.join(' - ')
|
70
|
-
end
|
66
|
+
log_entry
|
71
67
|
end
|
72
68
|
|
73
69
|
def self.app_name
|
@@ -1,9 +1,9 @@
|
|
1
1
|
redis_url = ENV["REDIS_URL"].present? ? ENV["REDIS_URL"] : defined?(Rails.application.secrets.redis) ? Rails.application.secrets.redis : 'redis://localhost:6379/1'
|
2
2
|
resque_url = ENV["RESQUE_URL"].present? ? ENV["RESQUE_URL"] : defined?(Rails.application.secrets.resque) ? Rails.application.secrets.resque : 'redis://localhost:6379/1'
|
3
3
|
if defined?(Redis.current)
|
4
|
-
Redis.current = Redis.new(:id => "#{ZuoraConnect::Telegraf.full_process_name(process_name: 'Redis')}", :url => redis_url, :timeout =>
|
4
|
+
Redis.current = Redis.new(:id => "#{ZuoraConnect::Telegraf.full_process_name(process_name: 'Redis')}", :url => redis_url, :timeout => 10, :reconnect_attempts => 2)
|
5
5
|
if defined?(Resque.redis)
|
6
|
-
Resque.redis = resque_url != redis_url ? Redis.new(:id => "#{ZuoraConnect::Telegraf.full_process_name(process_name: 'Resque')}", :url => resque_url, :timeout =>
|
6
|
+
Resque.redis = resque_url != redis_url ? Redis.new(:id => "#{ZuoraConnect::Telegraf.full_process_name(process_name: 'Resque')}", :url => resque_url, :timeout => 10, :reconnect_attempts => 2) : Redis.current
|
7
7
|
end
|
8
8
|
end
|
9
9
|
if defined?(RedisBrowser)
|
@@ -19,13 +19,4 @@ Resque.module_eval do
|
|
19
19
|
|
20
20
|
Hash[queue_names.zip(sizes)]
|
21
21
|
end
|
22
|
-
end
|
23
|
-
|
24
|
-
if defined?(Resque)
|
25
|
-
Resque.logger = ZuoraConnect.custom_logger(name: "Resque", type: 'Monologger', level: MonoLogger::INFO)
|
26
|
-
Resque::Scheduler.logger = ZuoraConnect.custom_logger(name: "ResqueScheduler") if defined?(Resque::Scheduler)
|
27
|
-
end
|
28
|
-
|
29
|
-
Makara::Logging::Logger.logger = ZuoraConnect.custom_logger(name: "Makara") if defined?(Makara)
|
30
|
-
ElasticAPM.agent.config.logger = ZuoraConnect.custom_logger(name: "ElasticAPM", level: MonoLogger::WARN) if defined?(ElasticAPM) && ElasticAPM.running?
|
31
|
-
ActionMailer::Base.logger = ZuoraConnect.custom_logger(name: "ActionMailer", type: 'Monologger') if defined?(ActionMailer)
|
22
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class AddTokensToAppInstance < ActiveRecord::Migration
|
1
|
+
class AddTokensToAppInstance < ActiveRecord::Migration[4.2]
|
2
2
|
def change
|
3
3
|
add_column :zuora_connect_app_instances, :access_token, :string unless column_exists? :zuora_connect_app_instances, :access_token
|
4
4
|
add_column :zuora_connect_app_instances, :refresh_token, :string unless column_exists? :zuora_connect_app_instances, :refresh_token
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class AddExpirationToAppInstance < ActiveRecord::Migration
|
1
|
+
class AddExpirationToAppInstance < ActiveRecord::Migration[4.2]
|
2
2
|
def change
|
3
3
|
add_column :zuora_connect_app_instances, :oauth_expires_at, :datetime unless column_exists? :zuora_connect_app_instances, :oauth_expires_at
|
4
4
|
end
|