Class: AcidicJob::Serializers::JobSerializer

Inherits:
ActiveJob::Serializers::ObjectSerializer
  • Object
show all
Defined in:
lib/acidic_job/serializers/job_serializer.rb

Instance Method Summary collapse

Instance Method Details

#deserialize(hash) ⇒ Object



16
17
18
19
20
# File 'lib/acidic_job/serializers/job_serializer.rb', line 16

def deserialize(hash)
  job = ::ActiveJob::Base.deserialize(hash)
  job.send(:deserialize_arguments_if_needed)
  job
end

#serialize(job) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/acidic_job/serializers/job_serializer.rb', line 8

def serialize(job)
  # don't serialize the `enqueued_at` value, as ActiveRecord will check if the Run record has changed
  # by comparing the deserialized database value with a temporary in-memory generated value.
  # That temporary in-memory generated value can sometimes have an `enqueued_at` value that is 1 second off
  # from the original. In this case, ActiveRecord will think the record has unsaved changes and block the lock.
  super(job.serialize.except("enqueued_at"))
end

#serialize?(argument) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/acidic_job/serializers/job_serializer.rb', line 22

def serialize?(argument)
  defined?(::ActiveJob::Base) && argument.class < ::ActiveJob::Base
end