Module: AcidicJob::Arguments
- Extended by:
- Arguments
- Includes:
- ActiveJob::Arguments
- Included in:
- Arguments
- Defined in:
- lib/acidic_job/arguments.rb
Instance Method Summary collapse
-
#convert_to_global_id_hash(argument) ⇒ Object
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.
-
#deserialize_global_id(hash) ⇒ Object
‘ActiveJob` will throw an error if it tries to deserialize a GlobalID record.
Instance Method Details
#convert_to_global_id_hash(argument) ⇒ Object
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.
25 26 27 28 29 |
# File 'lib/acidic_job/arguments.rb', line 25 def convert_to_global_id_hash(argument) { GLOBALID_KEY => argument.to_global_id.to_s } rescue ::URI::GID::MissingModelIdError ::ActiveJob::Serializers.serialize(argument) end |
#deserialize_global_id(hash) ⇒ Object
‘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.
17 18 19 20 21 |
# File 'lib/acidic_job/arguments.rb', line 17 def deserialize_global_id(hash) ::GlobalID::Locator.locate hash[GLOBALID_KEY] rescue ::ActiveRecord::RecordNotFound nil end |