Search code examples
ruby-on-railsdelayed-jobuuidrails-activejobdelayed-paperclip

ActiveJob::SerializationError with ActiveUUID


I'm getting the following Error:

    [ActiveJob] Enqueued DelayedPaperclip::Jobs::ActiveJob (Job ID: 78975c5c-7da2-4a70-a156-91cda1c53013) to DelayedJob(paperclip) with arguments: "Video", #<UUID:0x3fc83523c368 UUID:b543e798-ad01-4416-b8fb-9ddb0d31a6ce>, "video"
Completed 500 Internal Server Error in 96195ms (ActiveRecord: 1.5ms)

ActiveJob::SerializationError (Unsupported argument type: UUIDTools::UUID):
  app/controllers/video_controller.rb:11:in `create'

While using these gems:

  • activeuuid
  • paperclip
  • delayed_job
  • delayed_paperclip

This is my actual model code:

class Video < ActiveRecord::Base
  include ActiveUUID::UUID

  belongs_to :timeline
  has_attached_file :video,
                    :styles => {
                        :thumb => { :geometry => "360x360#", :format => 'jpg', :time => 1 },
                        :lowres => { :geometry => "360x360#", :format => 'mp4' }
                    }, only_process: [:thumb], :processors => [:transcoder],
                    :path => ":class/:id/:style/:basename.:extension"

  validates_attachment_content_type :video, :content_type => ["video/mp4", "video/mov", "video/mpeg","video/mpeg4", "video/quicktime", "image/jpg", "image/jpeg"]

  process_in_background :video, only_process: [:lowres]

So I'm guessing the error is coming from activeuuid or delayed_paperclip as ActiveJob can't handle or recognize the Object.

Has anyone got an idea how to fix this?


Solution

  • ActiveJob tries to serialize the arguments to be sent to the backend (sidekiq, dj, etc). Only JSON serializable objects are accepted plus GlobalIDs. The quickest solution for you is to pass your uuid as string and rebuild the uuid in your job.

    # enqueue
    VideoJob.perform_later uuid.to_s
    # job class
    class VideoJob
      def perform(uuid_string)
        uuid = UUIDTools::UUID.parse(uuid_string)
        # do whatever you need to do
      end
    end