QueueClassic/queue_classic

Unable to pass Active record objects as arguments

Closed this issue · 5 comments

I had to deal with active record objects extensively. I did it with delayed_job without any issues. But when I tried to use queue_classic. I am always getting an error as:

  NoMethodError: undefined method `key?' for #<JSON::Ext::Generator::State:0xa0d640c>

After deep observation, I think I got this error only when I tried to pass active record objects as an argument.

Is queue_classic unable to handle this ?

This sounds unsafe to do. I might be wrong, but what would happen if you use that serialized object and save it, but before doing that, you/someone updated the same record in another job or page? Answer: messed up data. AFAIK, the best practice when queueing jobs is to give ids, not the objects.

That said, I am not saying it should not work (I never tried it myself) so I'll let someone else decide wether it is making sense to have that working...

What version of queue_classic are you using?

It is true that queue_classic is unable to handle the enqueueing of complex objects. The enqueue interface was designed to accept simple objects. In the case of an AR object you are better off to enqueue an id to that object and then read the id's data from the database at the time you are working on the job. This allows you to open a transaction during the working of the job to ensure that you are operating on the object's data in a safe fashion.

I am using queue_classic 3.0.0beta.
As you said that the queue_classic is unable to handle the complex objects, please let me know, whether the queue_classic handle large JSON data or not. Because, I have to get huge data from AppNexus API and pass as an argument to the queue_classic.

Closing as there was no activity for months.

This is related to Active Job as well. It will allow to pass Active Record instances using globalid. As far as QC itself goes, you shouldn't pass AR instances directly. These objects are not easily serializable so it's advised to just pass the id and fetch it again on the job side of things.