librelist archives

« back to archive

ActiveRecord extension: Why serialize the object instead of just storing the primary key?

ActiveRecord extension: Why serialize the object instead of just storing the primary key?

From:
Martin Schürrer
Date:
2012-08-24 @ 11:17
Hi!

I looked at 
https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/extensions/active_record.rb

# User.recent_signups.each { |user| user.delay.mark_as_awesome }
#
# Please note, this is not recommended as this will serialize the entire
# object to Redis.  Your Sidekiq jobs should pass IDs, not entire instances.
# This is here for backwards compatibility with Delayed::Job only.

Why wouldn't Sidekiq just push the object type, the primary id and the
method instead of serializing the object?

Also why does MyModel.delay.process_something return true instead of
the sidekiq job id?

Cheers,
Martin

Re: [sidekiq] ActiveRecord extension: Why serialize the object instead of just storing the primary key?

From:
Mike Perham
Date:
2012-08-24 @ 15:13
Because you might have transient state in the instance that affects
the operation.  You can easily do:

User.delay.some_operation(user.id)

but Sidekiq does not assume to take that shortcut for you.


On Fri, Aug 24, 2012 at 4:17 AM, Martin Schürrer <martin@schuerrer.org> wrote:
> Hi!
>
> I looked at 
https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/extensions/active_record.rb
>
> # User.recent_signups.each { |user| user.delay.mark_as_awesome }
> #
> # Please note, this is not recommended as this will serialize the entire
> # object to Redis.  Your Sidekiq jobs should pass IDs, not entire instances.
> # This is here for backwards compatibility with Delayed::Job only.
>
> Why wouldn't Sidekiq just push the object type, the primary id and the
> method instead of serializing the object?
>
> Also why does MyModel.delay.process_something return true instead of
> the sidekiq job id?