Class: Barbeque::JobQueuesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Barbeque::JobQueuesController
- Defined in:
- app/controllers/barbeque/job_queues_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #sqs_attributes ⇒ Object
- #sqs_metrics ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 22 def create @job_queue = Barbeque::JobQueue.new(params.require(:job_queue).permit(:name, :description)) @job_queue.queue_url = create_queue(@job_queue).queue_url if @job_queue.valid? if @job_queue.save redirect_to @job_queue, notice: 'Job queue was successfully created.' else render :new end end |
#destroy ⇒ Object
43 44 45 46 47 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 43 def destroy @job_queue = Barbeque::JobQueue.find(params[:id]) @job_queue.destroy redirect_to job_queues_url, notice: 'Job queue was successfully destroyed.' end |
#edit ⇒ Object
18 19 20 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 18 def edit @job_queue = Barbeque::JobQueue.find(params[:id]) end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 6 def index @job_queues = Barbeque::JobQueue.all end |
#new ⇒ Object
14 15 16 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 14 def new @job_queue = Barbeque::JobQueue.new end |
#show ⇒ Object
10 11 12 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 10 def show @job_queue = Barbeque::JobQueue.find(params[:id]) end |
#sqs_attributes ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 49 def sqs_attributes job_queue = Barbeque::JobQueue.find(params[:id]) attributes = self.class.sqs_client.get_queue_attributes( queue_url: job_queue.queue_url, attribute_names: %w[ ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible RedrivePolicy QueueArn ], ).attributes dlq_metrics = if attributes['RedrivePolicy'] dlq_arn = JSON.parse(attributes['RedrivePolicy']).fetch('deadLetterTargetArn') dlq_name = queue_name_from_arn(dlq_arn) dlq_url = self.class.sqs_client.get_queue_url(queue_name: dlq_name).queue_url dlq_attributes = self.class.sqs_client.get_queue_attributes( queue_url: dlq_url, attribute_names: %w[ ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible ], ).attributes.transform_values(&:to_i) { queue_name: dlq_name, attributes: dlq_attributes, } else nil end render json: { queue_name: queue_name_from_arn(attributes['QueueArn']), attributes: { 'ApproximateNumberOfMessages' => attributes['ApproximateNumberOfMessages'].to_i, 'ApproximateNumberOfMessagesNotVisible' => attributes['ApproximateNumberOfMessagesNotVisible'].to_i, }, dlq: dlq_metrics, } end |
#sqs_metrics ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 89 def sqs_metrics queue_name = params[:queue_name] unless queue_name.present? render status: 400, json: { error: 'params[:queue_name] is required' } return end metric_name = params[:metric_name] unless metric_name.present? render status: 400, json: { error: 'params[:metric_name] is required' } return end statistic = params[:statistic] unless statistic.present? render status: 400, json: { error: 'params[:statistic] is required' } return end now = Time.zone.now from = now - 24.hours resp = self.class.cloudwatch_client.get_metric_statistics( namespace: 'AWS/SQS', metric_name: metric_name, dimensions: [ { name: 'QueueName', value: queue_name }, ], start_time: from, end_time: now, period: compute_minimum_period(from, now), statistics: [statistic], ) render json: { label: resp.label, datapoints: resp.datapoints.sort_by(&:timestamp).map { |datapoint| { timestamp: Time.zone.at(datapoint.), value: datapoint[statistic.underscore], } }, } end |
#update ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/barbeque/job_queues_controller.rb', line 33 def update @job_queue = Barbeque::JobQueue.find(params[:id]) # Name can't be changed after it's created. if @job_queue.update(params.require(:job_queue).permit(:description)) redirect_to @job_queue, notice: 'Job queue was successfully updated.' else render :edit end end |