Skip to content
This repository was archived by the owner on Jun 16, 2024. It is now read-only.

Commit c817e17

Browse files
committed
shoryuken
1 parent 98e1d39 commit c817e17

File tree

9 files changed

+102
-1
lines changed

9 files changed

+102
-1
lines changed

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ gem 'aws-sdk-chimesdkidentity'
1515
gem 'aws-sdk-chimesdkmessaging'
1616
gem 'aws-sdk-ivs'
1717

18+
gem 'shoryuken'
19+
gem 'aws-sdk-sqs'
20+
1821
gem 'simpacker'
1922
gem 's3_assets_uploader'
2023

Gemfile.lock

+9
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ GEM
8383
aws-sdk-core (~> 3, >= 3.119.0)
8484
aws-sdk-kms (~> 1)
8585
aws-sigv4 (~> 1.1)
86+
aws-sdk-sqs (1.43.0)
87+
aws-sdk-core (~> 3, >= 3.119.0)
88+
aws-sigv4 (~> 1.1)
8689
aws-sdk-transcribestreamingservice (1.31.0)
8790
aws-sdk-core (~> 3, >= 3.119.0)
8891
aws-sigv4 (~> 1.1)
@@ -208,6 +211,10 @@ GEM
208211
sentry-ruby-core (4.7.1)
209212
concurrent-ruby
210213
faraday
214+
shoryuken (5.2.3)
215+
aws-sdk-core (>= 2)
216+
concurrent-ruby
217+
thor
211218
simpacker (1.2.0)
212219
railties (>= 4.2)
213220
sprockets (4.0.2)
@@ -236,6 +243,7 @@ DEPENDENCIES
236243
aws-sdk-core
237244
aws-sdk-ivs
238245
aws-sdk-s3
246+
aws-sdk-sqs
239247
aws-sdk-transcribestreamingservice
240248
barnes
241249
byebug
@@ -250,6 +258,7 @@ DEPENDENCIES
250258
sass-rails (>= 6)
251259
sentry-rails
252260
sentry-ruby
261+
shoryuken
253262
simpacker
254263

255264
BUNDLED WITH

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
release: bundle exec rake db:migrate assets:upload
22
web: bundle exec puma -p $PORT -C config/puma.rb
3+
worker: bundle exec shoryuken start -R -C config/shoryuken.yml

app/controllers/api/control/track_cards_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def index
1212

1313
def create
1414
TrackCard.create!(track_card_params)
15-
EmitIvsMetadataJob.perform_later
15+
EmitIvsMetadataJob.perform_now
1616
render(json: {ok: true}.to_json)
1717
end
1818

app/jobs/application_job.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
class ApplicationJob < ActiveJob::Base
2+
queue_as ENV["TAKEOUT_SHORYUKEN_QUEUE"] if ENV["TAKEOUT_SHORYUKEN_QUEUE"]
23
end

config/initializers/shoryuken.rb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module Shoryuken
2+
module Middleware
3+
module Server
4+
class RavenReporter
5+
def call(worker_instance, queue, sqs_msg, body)
6+
#tags = {}
7+
#context = { message: body }
8+
Sentry.with_scope do
9+
scope.set_transaction_name(body['job_class'])
10+
scope.set_tags( job: body['job_class'], queue: queue )
11+
begin
12+
yield
13+
rescue Exception => e
14+
Sentry.capture_exception(e)
15+
raise
16+
end
17+
end
18+
end
19+
end
20+
end
21+
end
22+
end
23+
24+
Shoryuken.active_job_queue_name_prefixing = false
25+
26+
if ENV['TAKEOUT_SHORYUKEN_QUEUE']
27+
Shoryuken.configure_client do |config|
28+
config.sqs_client = Aws::SQS::Client.new(region: ENV.fetch('TAKEOUT_SHORYUKEN_AWS_REGION'), logger: Rails.logger)
29+
end
30+
Shoryuken.configure_server do |config|
31+
config.server_middleware do |chain|
32+
chain.add Shoryuken::Middleware::Server::RavenReporter
33+
end
34+
35+
config.sqs_client = Aws::SQS::Client.new(region: ENV.fetch('TAEKOUT_SHORUKEN_AWS_REGION'), logger: Rails.logger)
36+
# see also config/shoryuken.yml
37+
config.sqs_client_receive_message_opts = { wait_time_seconds: 20 }
38+
end
39+
end

config/shoryuken.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
concurrency: <%= ENV.fetch('RAILS_MAX_THREADS', 10) %>
2+
# ActiveJob prefixes queue name, the default delimiter is `_`
3+
queues:
4+
- [<%= ENV.fetch('TAKEOUT_SHORYUKEN_QUEUE') %>, 1]

tf/iam_heroku-takeout-prd.tf

+21
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ data "aws_iam_policy_document" "heroku-takeout-prd" {
8282
"arn:aws:ivs:us-west-2:005216166247:channel/oTssPyKzhjoS",
8383
]
8484
}
85+
86+
statement {
87+
effect = "Allow"
88+
actions = [
89+
"sqs:ChangeMessageVisibility",
90+
"sqs:ChangeMessageVisibilityBatch",
91+
"sqs:DeleteMessage",
92+
"sqs:DeleteMessageBatch",
93+
"sqs:GetQueueAttributes",
94+
"sqs:GetQueueUrl",
95+
"sqs:ReceiveMessage",
96+
"sqs:SendMessage",
97+
"sqs:SendMessageBatch",
98+
"sqs:ListQueues",
99+
]
100+
resources = [
101+
aws_sqs_queue.activejob-prd.arn,
102+
aws_sqs_queue.activejob-dlq-prd.arn,
103+
]
104+
}
105+
85106
}
86107

87108
resource "aws_iam_user_policy" "heroku-takeout-prd" {

tf/sqs.tf

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resource "aws_sqs_queue" "activejob-prd" {
2+
provider = aws.use1
3+
name = "takeout-app-activejob-prd"
4+
5+
redrive_policy = jsonencode({
6+
deadLetterTargetArn = aws_sqs_queue.activejob-dlq-prd.arn
7+
maxReceiveCount = 10
8+
})
9+
10+
tags = {
11+
Environment = "production"
12+
}
13+
}
14+
15+
16+
resource "aws_sqs_queue" "activejob-dlq-prd" {
17+
provider = aws.use1
18+
name = "takeout-app-activejob-dlq-prd"
19+
20+
tags = {
21+
Environment = "production"
22+
}
23+
}

0 commit comments

Comments
 (0)