class Quebert::Serializer::Job

Does this mean you could queue a job that could queue a job? Whoa!

Public Class Methods

deserialize(hash) click to toggle source
# File lib/quebert/serializer.rb, line 17
def self.deserialize(hash)
  hash = Support.stringify_keys(hash)
  job = Support.constantize(hash['job']).new(*deserialize_args(hash['args']))
  job.priority = hash['priority']
  job.delay = hash['delay']
  job.ttr = hash['ttr']
  job.queue = hash['queue']
  job
end
serialize(job) click to toggle source
# File lib/quebert/serializer.rb, line 6
def self.serialize(job)
  {
    'job' => job.class.name,
    'args' => serialize_args(job.args),
    'priority' => job.priority,
    'delay' => job.delay,
    'ttr' => job.ttr,
    'queue' => job.queue
  }
end

Private Class Methods

deserialize_args(args) click to toggle source

Find a serializer and/or push out a value

# File lib/quebert/serializer.rb, line 44
def self.deserialize_args(args)
  args.map do |arg|
    arg = Support.stringify_keys(arg)
    if arg.key? 'serializer' and serializer = Support.constantize(arg['serializer'])
      serializer.deserialize(arg['payload'])
    else
      arg['payload']
    end
  end
end
serialize_args(args) click to toggle source

Reflect on each arg and see if it has a seralizer

# File lib/quebert/serializer.rb, line 30
def self.serialize_args(args)
  args.map do |arg|
    hash = Hash.new
    if serializer = Quebert.serializers[arg.class]
      hash['serializer'] = serializer.name
      hash['payload'] = serializer.serialize(arg)
    else
      hash['payload'] = arg
    end
    hash
  end
end