In ruby on rails, SideKiq is used for background tasks. railssidekiq

Source: Internet
Author: User
Tags ruby on rails install redis

In ruby on rails, SideKiq is used for background tasks. railssidekiq

Environment: ubuntu14.4, ruby2.1.5, rails4.2

1. A new rais project: rails new active_job -- skip-Bundle

Enter the project folder: cd active_job

Open the Gemfile: vim Gemfile

Change source 'https: // rubygems.org 'to source 'https: // ruby.taobao.org' and add: G' sidekiq 'to the file'

Run: bundle install

Ii. install redis-server: sudo apt-get install redis-server

Redis-cli enters redis and runs ping

PONG indicates that the installation is successful.

Iii. Try sidekiq

Run sidekiq To Go To The task monitoring page.

:

  

 

Iv. test:

Create job: rails g job restJob

The rest_job.rb file is generated in the app/jobs folder. open the file vim rest_job.rb and modify the perform method. Add puts "SideKiq test" as a test. Save and exit.

Add config. active_job.queue_adapter =: sidekiq in config/application. rb.

Rails Console: rails c

Input: REstJob. set (wait: 1. minutes). Choose m_later

If no error is reported, the task is successfully added.

    

The entered"SideKiq Test":

  

  

This indicates that everything is running normally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.