Skip to content

Instantly share code, notes, and snippets.

@miyamae
Last active December 17, 2015 19:59
Show Gist options
  • Save miyamae/5664554 to your computer and use it in GitHub Desktop.
Save miyamae/5664554 to your computer and use it in GitHub Desktop.
Rails4でwheneverのrunnerジョブを定義する方法

Rails4だとscript/runnerがないので、今のところ(2013/5時点)wheneverのrunnerジョブが使えない。

そこで次のような感じで独自のjob_typeを定義すればok。

job_type :rails4_runner, "cd :path && bin/rails runner -e :environment :task.execute :output"

every 1.day, at: '01:00' do
  rails4_runner 'Tasks::HogeTask'
end

処理はこんな感じで。lib/tasks/hoge_task.rb

class Tasks::HogeTask
  def self.execute
    User.job!
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment