-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharound_action.rb
38 lines (30 loc) · 1.22 KB
/
around_action.rb
1
2
3
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
class BenchmarkFilter
def self.filter(controller)
timer = Time.now
Rails.logger.debug "---#{controller.controller_name} #{controller.action_name}"
yield # 這裡執行Action動作
elapsed_time = Time.now - timer
Rails.logger.debug "---#{controller.controller_name} #{controller.action_name} finished in %0.2f" % elapsed_time
end
end
class EventsControler < ApplicationController
around_action BenchmarkFilter
end
# around_action 可以加一个类,也可以加具体的方法
def save_notice
log_id = SecureRandom.uuid
request_options = {}
request_options[:log_id] = log_id
request_options[:request_at] = Time.now
request_options[:params] = params.except(:action, :controller)
YtxappInboxNoticeWorker.perform_async :ivr_request, request_options
consuming = Benchmark.measure{ yield }.real
response_options = {}
response_options[:log_id] = log_id
response_options[:consuming] = consuming
response_options[:response_at] = Time.now
response_options[:response_body] = response.body
YtxappInboxNoticeWorker.perform_in 20.seconds, :ivr_response, response_options
end
around_action :save_notice
# save_notice 方法中需要有yield,action就是回调执行在yield中