LoginSignup
0
0

More than 1 year has passed since last update.

#Rails + shoryuken gem + #AWS SQS でリトライ処理の動作確認をする

Last updated at Posted at 2019-09-17

ランダムに失敗するジョブを作っておく

class ShoryukenRandomFailureJob < ApplicationJob
  queue_as :example1
  queue_as :example2

  def perform(message)
    if rand(1..3) <= 1
      puts '-' * 100
      puts 'JOB WOKED'
      puts '-' * 100
      puts "message: #{message}"
      puts '-' * 100
    else
      raise 'Job Failed'
    end
  end
end

ジョブを実行する

bundle exec rails runner 'ShoryukenRandomFailureJob.perform_later("ABC")'

Workerで例外が確認できる

image

AWS SQS のコンソールで処理中のメッセージが増える

image

いずれジョブが成功する

image

Workerがメッセージ = ジョブを自動削除して、処理中のメッセージ数が0になる

image

ただし shoryuken worker の設定で自動削除を有効化している場合に限る

class ShoryukenWorker
  include Shoryuken::Worker

  shoryuken_options queue: 'example1', auto_delete: true
  shoryuken_options queue: 'example2', auto_delete: true
  shoryuken_options queue: 'example3', auto_delete: true
end

NOTE

  • shoryuken的にリトライをしているか、SQS的にリトライをしているかはまだ不明

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0