Class: HousingMisc::SidekiqQueueCheckController
Constant Summary
collapse
- DEFAULT_QUEUE_SIZE =
100
- DEFAULT_TOTAL_SIZE =
1000
Constants included
from ApiHelper
ApiHelper::MOBILE_REQUEST_TIME_THRESHOLD
Instance Method Summary
collapse
Methods included from ApiHelper
#add_attachments, #add_base_vars, #add_global_merge_vars, #add_merge_vars, #add_user_emails, #csrf_check, #filter_parameters, #get_api_call, #get_email_template_from_mail_service, #get_past_channel_details, #get_request_attribute_value, #get_shortened_url, #internal_host_check, #is_request_csrf_valid?, #is_request_from_mobile?, #is_request_internal?, #log_invalid_csrf_request, #logging_file, #send_generic_mail, #send_generic_sms, #upload_log_to_s3
#new_relic_custom_params
#render
Instance Method Details
#alert_slack(url, message) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'app/controllers/housing_misc/sidekiq_queue_check_controller.rb', line 52
def alert_slack(url, message)
url = URI(url)
req = Net::HTTP::Post.new url.path
req.body = {:text => message}.to_json
res = Net::HTTP.start(url.host, url.port, :use_ssl => true) do |http|
http.request req
end
end
|
#check ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'app/controllers/housing_misc/sidekiq_queue_check_controller.rb', line 12
def check
return unless check_sidekiq_presence
require "sidekiq/api"
jobs_info = get_above_threshold_queue_list
alert_slack(HousingMisc.sidekiq_message_url, get_message(jobs_info)) unless jobs_info.empty?
jobs_info = {"message" => "no sidekiq queue above threshold"} if jobs_info.empty?
render json: jobs_info
end
|
#check_permission ⇒ Object
8
9
10
|
# File 'app/controllers/housing_misc/sidekiq_queue_check_controller.rb', line 8
def check_permission
return false
end
|
#check_sidekiq_presence ⇒ Object
46
47
48
49
50
|
# File 'app/controllers/housing_misc/sidekiq_queue_check_controller.rb', line 46
def check_sidekiq_presence
return true if Gem.loaded_specs["sidekiq"].present?
render json: {"message" => "no sidekiq in this service"}
return false
end
|
#get_above_threshold_queue_list ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/housing_misc/sidekiq_queue_check_controller.rb', line 22
def get_above_threshold_queue_list
jobs_info = {}
stats = Sidekiq::Stats.new
total_threshold = HousingMisc.sidekiq_custom_threshold["total"] || DEFAULT_TOTAL_SIZE
if stats.enqueued > total_threshold
jobs_info["total"] = {"jobs" => stats.enqueued, "threshold" => total_threshold }
end
stats.queues.each do |key, value|
queue_threshold = HousingMisc.sidekiq_custom_threshold[key] || DEFAULT_QUEUE_SIZE
if value > queue_threshold
jobs_info[key] = {"jobs" => value, "threshold" => queue_threshold }
end
end
jobs_info
end
|
#get_message(jobs_info) ⇒ Object
38
39
40
41
42
43
44
|
# File 'app/controllers/housing_misc/sidekiq_queue_check_controller.rb', line 38
def get_message(jobs_info)
message = "#{Time.now.to_s} :: Queues with jobs exceeding threshold in #{Rails.application.class.parent_name} service => "
jobs_info.each do |key, value|
message += " #{key} : #{value["jobs"]} jobs (Threshold : #{value["threshold"]}), "
end
message
end
|