require 'que'

module ActiveJob
  module QueueAdapters
    class QueAdapter
      class << self
        def enqueue(job, *args)
          JobWrapper.enqueue job, *args, queue: job.queue_name
        end

        def enqueue_at(job, timestamp, *args)
          raise NotImplementedError
        end
      end

      class JobWrapper < Que::Job
        def run(job, *args)
          job.new.execute *args
        end
      end
    end
  end
end

require 'que'

module ActiveJob
  module QueueAdapters
    class QueAdapter
      class << self
        def enqueue(job, *args)
          JobWrapper.enqueue job.to_s, *args, queue: job.queue_name
        end

        def enqueue_at(job, timestamp, *args)
          raise NotImplementedError
        end
      end

      class JobWrapper < Que::Job
        def run(job, *args)
          job.constantize.new.execute *args
        end
      end
    end
  end
end

Fix database serialization of job class names with Que
Fix database serialization of job class names with Que

When passing a class constant as a job argument, Que’s stored procedures serialize it to JSON in the database as `{}`. This means that when the job (the ActiveJob “wrapper”) is deserialized from the database, it can’t find the original job class to run again.

Changing the Que adapter to serialize the job class as a string fixes this behaviour. This change makes the adapter consistent with other adapters too (which constantize a class string in their JobWrapper#perform methods.