Environment: ubuntu14.4,ruby2.1.5, rails4.2
Sidetip relies on Sidekiq, so add Sidekiq in Gemfile.
A new Rais project: Rails new Schedule_job--skip-bundle
Go to project folder: CD Schedule_job
Open gemfile file: Vim gemfile
Change source ' https://rubygems.org ' to source ' https://ruby.taobao.org '.
Added in file: Gem ' Sidekiq ', Gem ' Sidetip '
Then run: Bundle install
Installing Redis-server:sudo apt-get Install Redis-server
Redis-cli into Redis, run ping
Pong indicates that the installation was successful.
second, the new test file:
Create a file under the App/jobs folder , create a new Scheduled task class: Myschedule
Vim my_scheduleRB, modified to:
Class Myschedule
Include Sidekiq::worker
Include Sidetiq::schedulable
Recurrence {Daily}
def perform
Puts "Sidetip test"
End
End
Save exit.
Add in config/application.rb: Config.active_job.queue_adapter =: Sidekiq
Third, run Sidekiq, will appear as:
This is the task to be carried out by midnight.
Four, test:
Modify the My_schedule.rb file to:
Class Myschedule
Include Sidekiq::worker
Include Sidetiq::schedulable
Recurrence do
minutely (1)
End
def perform
Puts "Sidetip test"
End
End
Be executed every minute instead.
Execute the SIDEKIQ command, which will appear
Run successfully.
How to implement timed tasks in Rails Sidetip