
Rails開発チームのrafaelfranca氏は10月22日(現地時間)、Ruby on Railsの最新版「Rails 8.1」をリリースしたことを発表しました(公式ブログ)。Rails 8.1は、500人以上の貢献者による2,500件以上のコミットを含み、ShopifyやHEYなどの大規模サービスでもすでに本番運用されています。
以下注目ポイントをまとめました。
Active Jobの継続機能(Continuations)
Active Jobは長時間実行されるジョブをステップに分割し、再起動後も途中から再開できるようになりました。特にKamalのデプロイ時に有用で、短いシャットダウン猶予(30秒)にも対応可能です。
class ProcessImportJob < ApplicationJob
include ActiveJob::Continuable
def perform(import_id)
@import = Import.find(import_id)
# block format
step :initialize do
@import.initialize
end
# step with cursor, the cursor is saved when the job is interrupted
step :process do |step|
@import.records.find_each(start: step.cursor) do |record|
record.process
step.advance! from: record.id
end
end
# method format
step :finalize
end
private
def finalize
@import.finalize
end
end
構造化イベントレポート(Structured Event Reporting)
ログが人間だけでなく機械にも優しくなりました。新しいEvent Reporterは、Railsアプリケーションで構造化されたイベントを生成するための統一インターフェースを提供します。タグやコンテキスト付きでイベントを通知し、サブスクライバーが柔軟に処理することができます。
Rails.event.notify("user.signup", user_id: 123, email: "user@example.com")
ローカルCIの標準化
高速な開発マシンを活かして、クラウドに頼らないCI環境が構築可能になりました。HEYの3万件以上のテストもローカルで2分以内に完了します(クラウドでは10分以上必要だったもの)。
CI.run do
step "Setup", "bin/setup --skip-server"
step "Style: Ruby", "bin/rubocop"
step "Security: Gem audit", "bin/bundler-audit"
step "Security: Importmap vulnerability audit", "bin/importmap audit"
step "Security: Brakeman code analysis", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error"
step "Tests: Rails", "bin/rails test"
step "Tests: Seeds", "env RAILS_ENV=test bin/rails db:seed:replant"
# Requires the `gh` CLI and `gh extension install basecamp/gh-signoff`.
if success?
step "Signoff: All systems go. Ready for merge and deploy.", "gh signoff"
else
failure "Signoff: CI failed. Do not merge or deploy.", "Fix the issues and try again."
end
end
その他、Markdown対応の強化や、Kamalの認証情報取得機能の改良、非推奨アソシエーションの明示機能の追加など、さまざまな新機能・改良が行われています。
Rails 8.1は、開発者体験を一段と高める機能が満載です。詳細は公式CHANGELOGをご覧ください
