Is it safe to pass objects to a Resque job?

Is it safe to pass objects to a Resque job? For example:

Resque.enqueue(Foobar, @foo, @bar) 

Instead:

 Resque.enqueue(Foobar, @foo.id, @bar.id) 

Any flaw if I pass the object to?

+7
source share
4 answers

Resque github page says (https://github.com/defunkt/resque)

... your jobs should only accept arguments that can be encoded in JSON.

In addition, there is an effect that you must take into account: the object you are transmitting is copied. Let's say this is a database entry. If later, when the task will be executed, this object will be changed in the database, the work will not notice, it will work on its own copy. Depending on your requirements, this may or may not be desirable behavior.

If you pass the id this object, you can get the latest version of this job.

+11
source

what i do is Marshal.dump(object) and on the other hand i do Marshal.restore(object) works like a charm and it is fast ...

eg:

  @chart = chart_factory.build(chart_config) marshal_dump = Marshal.dump(@chart) Resque.enqueue(ChartsWorker, marshal_dump, url) 
+3
source

The main drawback that I see, in addition to passing large objects that will be serialized compared to identifiers, is that the objects are most likely to go out of sync, because, obviously, the task can be completed later.

In most cases, you definitely need to use identifiers.

+2
source

Passing completed objects to resque can lead to a lot of workload in Redis, as well as serialization overhead. This may not be a problem for you, but you should keep that in mind.

Personally, I prefer to insert identifiers.

0
source

All Articles