投稿

9月, 2021の投稿を表示しています

Delayed::Cron::Jobの使用方法

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...

M1 MacにRails環境を構築する

M1 MacにRails環境を構築する home brew https://brew.sh/index_ja インストール /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" rbenv https://github.com/rbenv/rbenv#installation インストール brew install rbenv brew upgrade rbenv ruby-build rbenv init RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install [version] rbenv global [ver] rbenv local [ver] ruby -v mysql インストール brew install --build-from-source mysql@[ver] echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc source .zshrc brew services restart mysql@[ver] mysql -uroot メモ If you need to have mysql@5.7 first in your PATH, run: For compilers to find mysql@5.7 you may need to set: export LDFLAGS="-L/opt/homebrew/opt/mysql@[ver]/lib" export CPPFLAGS="-I/opt/homebrew/opt/mysql@[ver]/include" For pkg-config to find mysql@5.7 you may need to set: export PKG_CONFIG_PATH="/opt/homebrew/opt/m...