Delayed::Cron::Jobの使用方法 公式 https://github.com/codez/delayed_cron_job#changing-the-schedule Delayed :: Cron :: Job とは Rails用のGemでDelayed :: Job の拡張機能であり、ジョブを実行式をcron形式で設定できる インストール Gemfile に以下の行を追記 gem delayed_cron_job bundle インストールを実行 $ bundle migration ファイルを作成、実行 ※ delayed_job_active_recordを使用している場合、delayed_jobs テーブルに cron カラムが追加される $ rails generate delayed_job:cron $ rails db:migrate 使用方法 以下の様に Delayed::Job クラスを呼び出し、引数に実行したいJob、実行時間を記載する Delayed::Job.enqueue(MyRepeatedJob.new, cron: '15 */6 * * 1-5') 若しくは ActivieJob を使用して以下の様に記述する MyJob.set(cron: '*/5 * * * *').perform_later スケジューリング 通常、アプリケーションをデプロイするタイミングで、全てのJobの設定が必要になる これを以下の様なスーパークラスを作成する事で簡単に行うことができる Custom CronJob superclass app/jobs/cron_job.rb : # Default configuration in `app/jobs/application_job.rb`, or subclass # ActiveJob::Base . class CronJob < ApplicationJob class_attribute :cron_expression class << self def schedule set(cr...
コメント
コメントを投稿