キュー全体をクリアせずに、Resque キューから特定のジョブを削除するにはどうすればいいですか? 質問する

キュー全体をクリアせずに、Resque キューから特定のジョブを削除するにはどうすればいいですか? 質問する

私は Resque ワーカーを使用してキュー内のジョブを処理しています。キューには 100 万を超える多数のジョブがあり、一部のジョブは削除する必要があります (エラーによって追加されたもの)。ジョブを含むキューを作成するのは簡単な作業ではないため、resque-web を使用してキューをクリアし、正しいジョブを再度追加することは私にとっては選択肢ではありません。

アドバイスをいただければ幸いです。ありがとうございます!

ベストアンサー1

resque のソース (Job クラス) にはそのようなメソッドがあります。それが必要なものだと思います :)

# Removes a job from a queue. Expects a string queue name, a
# string class name, and, optionally, args.
#
# Returns the number of jobs destroyed.
#
# If no args are provided, it will remove all jobs of the class
# provided.
#
# That is, for these two jobs:
#
# { 'class' => 'UpdateGraph', 'args' => ['defunkt'] }
# { 'class' => 'UpdateGraph', 'args' => ['mojombo'] }
#
# The following call will remove both:
#
#   Resque::Job.destroy(queue, 'UpdateGraph')
#
# Whereas specifying args will only remove the 2nd job:
#
#   Resque::Job.destroy(queue, 'UpdateGraph', 'mojombo')
#
# This method can be potentially very slow and memory intensive,
# depending on the size of your queue, as it loads all jobs into
# a Ruby array before processing.
def self.destroy(queue, klass, *args)

おすすめ記事