Sha256: 206d9c7c254047b1ea782f53361c5e2ea7334d5c2a38cd8951b2cff865aa4c99
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true require "active_job/arguments" module AcidicJob module Arguments include ActiveJob::Arguments extend self # rubocop:disable Style/ModuleFunction # `ActiveJob` will throw an error if it tries to deserialize a GlobalID record. # However, this isn't the behavior that we want for our custom `ActiveRecord` serializer. # Since `ActiveRecord` does _not_ reset instance record state to its pre-transactional state # on a transaction ROLLBACK, we can have GlobalID entries in a serialized column that point to # non-persisted records. This is ok. We should simply return `nil` for that portion of the # serialized field. def deserialize_global_id(hash) GlobalID::Locator.locate hash[GLOBALID_KEY] rescue ActiveRecord::RecordNotFound nil end # In order to allow our `NewRecordSerializer` a chance to work, we need to ensure that # ActiveJob's first attempt to serialize an ActiveRecord model doesn't throw an exception. def convert_to_global_id_hash(argument) { GLOBALID_KEY => argument.to_global_id.to_s } rescue URI::GID::MissingModelIdError Serializers.serialize(argument) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
acidic_job-0.9.0 | lib/acidic_job/arguments.rb |
acidic_job-0.8.8 | lib/acidic_job/arguments.rb |