LoginSignup
0
0

More than 1 year has passed since last update.

How to use Rails | Resque

Last updated at Posted at 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オープンチャットもご利用ください。

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