4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/resque/plugins/app_instance_job.rb', line 4
def around_perform(args)
case args.class.name
when "Array"
if args.first.is_a?(Hash)
data = args.first.merge({:worker_class => self.to_s})
else
data = {:worker_class => self.to_s, :args => args.to_json}
end
when "Hash"
data = args.merge({:worker_class => self.to_s})
end
if Rails.logger.is_a?(Ougai::Logger) && !Rails.env.development?
Rails.logger.with_fields = { zecs_service: data.transform_keys(&:to_sym), trace_id: SecureRandom.uuid }
end
begin
connection_count ||= 0
@appinstance = ZuoraConnect::AppInstance.find(args['app_instance_id'].to_i)
job_start_log
@appinstance.new_session(holding_pattern: true)
rescue ActiveRecord::RecordNotFound => exception
if Redis.current.zscore("AppInstance:Deleted", args['app_instance_id'].to_i).present?
Rails.logger.info("No instance found, purge")
ZuoraConnect::AppInstance.new(id: args['app_instance_id'].to_i).prune_data
return
else
raise
end
rescue ActiveRecord::StatementInvalid, PG::ConnectionBad => exception
Rails.logger.warn("Bad Connection Restart", exception)
Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
return
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => exception
Rails.logger.warn("Enqueue Job Again ~ 2 mins", exception)
@appinstance.queue_pause(time: 2.minutes.to_i)
Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
return
rescue Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError => exception
Rails.logger.warn("Enqueue Job Again ~ 2 mins", exception)
@appinstance.queue_pause(time: 2.minutes.to_i)
Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
return
end
yield
rescue
raise
ensure
@appinstance.cache_app_instance if defined?(@appinstance)
Rails.logger.flush if Rails.logger.methods.include?(:flush)
end
|