なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2016/08/03)

2016/08/03分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

activejob/CHANGELOG.md

activesupport/CHANGELOG.md


Remove extra connection pool creation

activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rbの修正です。

ActiveRecord::ConnectionAdapters::ConnectionHandler#establish_connectionメソッドから、不要なconnection poolの作成処理を削除しています。


Show supported DBs first in rails new --help

railties/lib/rails/generators/app_base.rbの修正です。

rails new --helpで表示するサポートしているDBのリストを、mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbcからmysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbcに修正しています。

サポートしているDBを先に表示する為との事です。


Add 4.2.Z back to the maintenance list

rails guideのMaintenance Policy for Ruby on Railsの修正です。

Bug Fixesの対象リストに4.2.Zを戻しています。何人かのcoreメンバーが5.1のリリースまで4.2のbug fixを続ける事に同意した為、との事です。へー。


Merge pull request #25991 from rails/retry-and-discard-jobs

Active Jobの修正です。

Job実行中にexceptionが発生した場合に、処理をリトライ、又は破棄する為のActiveJob::Base.retry_onActiveJob::Base.discard_onメソッドを追加しています。

例。

class RemoteServiceJob < ActiveJob::Base
  retry_on CustomAppException # デフォルトでは3秒waitし、5回再実行を行う
  retry_on AnotherCustomAppException, wait: ->(executions) { executions * 2 }
  retry_on ActiveRecord::StatementInvalid, wait: 5.seconds, attempts: 3
  retry_on Net::OpenTimeout, wait: :exponentially_longer, attempts: 10
  discard_on ActiveJob::DeserializationError

  def perform(*args)
    # Might raise CustomAppException or AnotherCustomAppException for something domain specific
    # Might raise ActiveRecord::StatementInvalid when a local db deadlock is detected
    # Might raise Net::OpenTimeout when the remote service is down
  end
end

waitexponentially_longerを指定すると、jobが失敗する毎にwait時間が長くなります(最初は3s, 次は18s, 次は83s…という具合い)。計算式は(executions ** 4) + 2)になっています。


Avoid duplicated set_inverse_instance for target scope

Active Recordの修正です。

target scopeに対して複数回set_inverse_instanceがよばれていたのを、一度だけ処理を行うようリファクタリングを行っています。


Add documentation for ActiveSupport::StringInquirer [ci skip]

activesupport/lib/active_support/string_inquirer.rbのdocの修正です。

ActiveSupport::StringInquirerのdocにActiveSupport::StringInquirerインスタンスを独自に作成して使う場合のexampleを追加しています。


Merge pull request #26026 from kamipo/tx_serialization_error_should_inherit_statement_invalid

activerecord/lib/active_record/errors.rbの修正です。

TransactionSerializationErrorの親クラスをActiveRecordErrorからStatementInvalidに変更しています。

TransactionSerializationErrorは、Introduce AR::TransactionSerializationError for transaction serialization failures or deadlocksで追加された、transactionがdeadlock(MySQL)になったり、serialization failure(PostgreSQLでtransactionの実行を直列に行うことができない状況になる場合におこるエラー)になったりした場合に使用する為のクラスなのですが、元々左記のような状況が起きた場合はStatementInvalidがraiseするようになっていた為、下位互換の為(既存のコードを変えずにエラーのハンドリングを出来るようにする為に)に、StatementInvalidを継承するよう修正したとの事です。


Merge pull request #25107 from Erol/introduce-new-ar-transaction-error-classes

Active Recordの修正です。

Introduce AR::TransactionSerializationError for transaction serialization failures or deadlocksで、transactionがdeadlock(MySQL)になったり、serialization failure(PostgreSQLでtransactionの実行を直列に行うことができない状況になる場合におこるエラー)になったりした場合TransactionSerializationErrorをraiseするよう対応されたのですが、異なるエラー(Serializationエラーとdeadlockエラー)を一つのエラークラスにまとめるのは良くないだろう、という事で、それぞれの場合で異なるエラークラス(SerializationFailure及びDeadlockDetected)を使用するよう修正しています。


Add :weeks to the list of variable duration parts

activesupport/lib/active_support/time_with_zone.rbの修正です。

ActiveSupport::TimeWithZone#duration_of_variable_length?メソッド内のduration partsのリストに:weeksを追加しています。

      def duration_of_variable_length?(obj)
-        ActiveSupport::Duration === obj && obj.parts.any? {|p| [:years, :months, :days].include?(p[0]) }
+        ActiveSupport::Duration === obj && obj.parts.any? {|p| [:years, :months, :weeks, :days].include?(p[0]) }
       end

[FIX] Change 1.week to create 1 week durations instead of 7 days durations1.week7 daysではなく、1 week durationsを返すようにした影響で、weeksもdurationのpartsになったのですが、上記チェックメソッドのリストに追加が漏れていた影響で、TimeWithZoneクラスにdurationの値を加算 / 減算した場合に正常な値が返ってこないバグがあったのを修正しています。

t = Date.parse('Mon, 24 Oct 2016').in_time_zone('Europe/Paris')
# => Mon, 24 Oct 2016 00:00:00 CEST +02:00
t + 7.days
# => Mon, 31 Oct 2016 00:00:00 CET +01:00
t + 1.week
# => Sun, 30 Oct 2016 23:00:00 CET +01:00

Don't require C dependencies on Windows/JRuby

Gemfileの修正です。

bladeblade-sauce_labs_plugingemにplatforms: [:ruby]オプションを追加しています。どちらもgemもWindows / JRubyでは動かない為のようです。