9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Resque覚書

9
Posted at

概要

  • Resque https://github.com/resque/resque
  • Rubyで動作するキュー制御のライブラリ。バックエンドはRedis
  • Resque.enqueue()でジョブをキューとして投入、Resque::Workerが投入されているジョブを拾い上げる→forkしたプロセス上でジョブを実行する
  • rakeから使うのが基本のようだが、rubyコードからも呼び出し可能
  • pluginが充実しているが、かなり内部構造をいじるpluginもあるため、pluginによっては競合する可能性がある。例えばresque-statresque-workers-lockは同時に使うのが困難な模様
  • 非常にシンプルな作りで、実行後のジョブがどのように終了したかなどは関知しない。基本ジョブ自身に丸投げ。

基本的な使い方

インストール

事前にredis serverが必要。Ubuntuならaptitude install redis-serverとかで。resque自身のインストールは以下のコマンド。

% gem install resque

ジョブクラス

require "resque"

class OreJob
  @queue = :ore_job_test

  def self.perform(*args)
    puts args[0]
    # working

  rescue Resque::TermException
    puts 'Interrupted'
  end
end

キュー作成

require "resque"
Resque.enqueue(OreJob, "hoge")

ワーカー

require "resque"
# ジョブクラスの@queueに指定した内容と同じものを引数で渡す
wk = Resque::Worker.new(:ore_job_test)
# wk.workを実行すると延々とキューを探し続ける
wk.work
9
9
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
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?