🖥

How to use Rails | Resque

2019/04/16に公開

1. Add a gem

Simply install resque.

 gem 'resque' 

 $ bundle install 

2. Write the content of execution

Write the processing you want the worker to execute in the perform method of the model. Here, as a test, create a process that only outputs standard.

 class Example @queue = :default def self.perform p 'Hello Sword!' end end 

3. Configure settings for workers

You only need to add one line to the Rakefile.

 require 'resque/tasks' 

4. Launch a worker

$ TERM_CHILD=1 QUEUES=* bundle exec rake environment resque:work

When launched, nothing happens now. That's because workers don't hesitate until the job is registered. Let's leave it for now.

image

5. Register a job

Let's add a job on another tab (separate window) from the worker. It's easy to use the Rails console.

$ bundle exec rails console

 irb(main)> Resque.enqueue(Example) => true 

If successful, true will be returned.

6. The job is run

After a few seconds, let's go back to the worker tab above. You will see that the job "standard output string" is being executed.

image

Congrats!

Premise

  • It is assumed that a Rails project has already been created.
  • It is assumed that bundler is already installed.

environment

  • resque (1.25.2)
  • Rails 4.2.4

Original by

Rails | Resque を動かす最小手順の使い方

About

About this translattion

チャットメンバー募集

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

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion