Olly Lylo
2008-Mar-18 00:05 UTC
[Backgroundrb-devel] Major issues with ActiveRecord callbacks in BackgroundRb r324
Hi there
I''ve been running BackgroundRb in production for a few months now.
Recently
we added encryption onto some of our ActiveRecord fields by hooking in the
before_save and after_save callbacks, like:
class MyCallback
def initialize(attr_names)
@attr_names = attr_names
end
def before_save(model)
@attr_names.each do |attr_name|
next if model.send("#{attr_name}").blank?
model.send("#{attr_name}=",
Encrypter.encrypt(model.send("#{attr_name}")))
end
end
def after_save(model)
@attr_names.each do |attr_name|
next if model.send("#{attr_name}").blank?
model.send("#{attr_name}=", Encrypter.decrypt(model.send
("#{attr_name}")))
end
end
end
There''s a little more to it but that should give you the idea. Anyway,
whilst this works a treat in our Rails app and when using script/console,
BackgroundRb returns strange results when we try and load a model object
which has an encrypted field. After some debugging it seems like the
before_save filter is called twice for these objects. When we access it
using the console, it''s only called once as expected.
Is there an obvious reason why adding bespoke callbacks like this might
cause a problem in a BackgroundRb worker? Failing this, would someone be
able to explain (or point me in the right direction of the class files) how
exactly BackgroundRb hooks into Rails? This way I can dig into the code to
investigate.
Thanks in advance
Olly
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080318/e04b7c5e/attachment.html
