1
2

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.

redis-cli で resque の job を追加

Posted at

cron で resque の job を追加したいんだけど、ruby が入ってない環境だったので、ruby なしで resque の job を追加する方法を調べた。

結論

class Foo
  @queue = "foo"
end

Resque.enque(Foo, 1, 2)

と同じことを redis-cli でやるなら下記でよい。

$ redis-cli sadd resque:queues foo
$ redis-cli rpush resque:queue:foo '{"class":"Foo","args":[1,2]}'

いちおう詳しく書くと、

  • resque:queues というセットにキュー名を追加
  • resque:queue:キュー名 というリストに {"class":クラス名,"args":引数の配列} な JSON を追加

調査の過程

resque-1.20.0/lib/resque.rb を読むと、下記の流れになる。

Resque.enqueue(klass, *args) ->
Resque.enqueue_to(queue, klass, *args) ->
(hook を実行して) Job.create(queue, klass, *args) ->
Resque.push(queue, class: klass.to_s, args: args)
Resque.push(queue: String, item: Hash)
-> redis.sadd(:queues, queue.to_s) # Resque.watch_queue 内で呼ばれる
-> redis.rpush "queue:#{queue}", encode(item)

Resque::Helpers#encode::MultiJson.encode(object)

また、Resque.redis= で namespace を resque にしている。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?