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.