🖥

Minimal steps to get Rails | resque-scheduler

2019/04/16に公開

1. Add a gem

In the familiar Gemfile. Install the resque body and the resque-scheduler.

 gem 'resque' gem 'resque-scheduler' 

 $ bundle install 

2. Write the processing content to the model

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

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

3. Add settings for workers

You only need to add two lines to the Rakefile.

 require 'resque/tasks' require 'resque/scheduler/tasks' 

4. Start up the resque worker

First of all, start the worker of resque itself. (not resque-scheduler's)

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

It will be in the following state.

image

Let's leave this and move on to the next.

5. Launch the resque-scheduler worker

It is necessary to launch separately from the worker of the resque body. So run in another window

$ bundle exec rake resque:scheduler

It will be in the following state.

image

6. Register a job

In addition, let's add a job in a separate window from the two workers. In other words, three windows are used.

It's easy to use the Rails console.

$ bundle exec rails console

 irb(main)> Resque.enqueue_in(5.second, Example) => true 

By the way, this means "register the job 5 seconds from now".

6. The job is run

After a while, let's look at the worker of the main body of resque, which was launched in step 1. You will see that the job "standard output string" is being executed.

image

Congrats!

environment

  • resque-scheduler (4.0.0)
  • resque (1.25.2)
  • Rails 4.2.4

Original by

Rails | resque-scheduler を動かす最小手順

About

About this translattion

チャットメンバー募集

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

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

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion