Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Object as argument in Resque-Worker

Is there a way to pass object as arguments value in Resque-workers.

I want to do something like this Resque.enqueue(SomeWorker, obj) instead of Resque.enqueue(SomeWorker, id) my object is of different kind which does not have id.

Appreciate any help.

like image 553
Bhushan Lodha Avatar asked Jan 25 '12 14:01

Bhushan Lodha


1 Answers

as a best practice, you should never pass a real object to a worker.

the idea is that you pass a minimum of information to your worker, idealy an id, so that the worker can retrieve the rest of the information itself.

since the data is persisted in redis, you would actually need to somehow marshal your object when queuing it and then unmarshal it when the worker retrieves the data.

if your object is just holding some data you should think about passing this as a hash, cause they are easily persistable within redis.

like image 117
phoet Avatar answered Nov 04 '22 00:11

phoet