Ruby on Rails
Friday, January 23, 2015
Hi all,
-- We just updated our app to rails 4.2, and implemented ActiveJob for our background jobs (were using Resque). I've read the docs and the code, and I couldn't find a "best practice" to accept custom types as job arguments.
I've managed to make a class serializable by mixing in GlobalID::Identification and implementing .find and #id methods. But then I started to have more errors, particularly with BigDecimal and ActiveRecord::AssociationRelation parameters.
The quick fix was to create an initializer and reopen ActiveJob::Arguments to override the serialize_argument method and accept those methods. I know it's not the best option as for example relation arguments would get converted to an array and it could be a lot of records.
So I wanted to know your opinion and how would you do it.
Other possible solution would be just to get the id of each record in the relation ( .pluck(:id) ) and then finding each record in the job worker again, but then what would be the point of having ActiveJob serialization?
Cheers!
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b2217f9c-6f02-4a96-8245-2e914b4a998e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment