美文网首页
Ruby&Rails---定时任务gem之crono

Ruby&Rails---定时任务gem之crono

作者: HPD_黄霹雳 | 来源:发表于2017-12-07 14:51 被阅读0次

github地址:https://github.com/plashchynski/crono

引入gem

gem 'crono'

运行构造器

rails generate crono:install

会创建一个config/cronotab.rb的配置文件,然后运行迁移

rake db:migrate

创建一个job

class TestJob < ApplicationJob
  queue_as :default

  def perform(*args)
     #你的任务
  end
end

在之前的config/cronotab.rb设置定时

Crono.perform(AppOralPracticeCommentAddPlayTimesJob).every 10.seconds

执行周期任务,在你的工程根目录下运行命令

bundle exec crono RAILS_ENV=development

相关文章

网友评论

      本文标题:Ruby&Rails---定时任务gem之crono

      本文链接:https://www.haomeiwen.com/subject/puhrixtx.html