How to implement timed tasks in Rails Sidetip

Source: Internet
Author: User
Tags install redis

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

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.