Delayed job object serialization and deserialization issue

Recently in one of our project there was a requirement to send SMS notification to users and task was to perform this functionality as background job using delayed job service. I wrote following code for sending SMS notifications to user and it was working fine. Then I just did one liner change in my code to process send_sms method asynchronously using handle_asynchronously method of delayed job and thought it will work as expected. attr_reader :client, :sender, :recepient, :message def initialize(recipient_ph_number, message_details) @client = Twilio::REST::Client.new ACCOUNT_SID, AUTH_TOKEN @sender = TWILIO_PHONE_

passing an unsaved object in delayed_job

In our recent project , we came across one scenario, where we had to pass an unsaved record as argument in background job. As delayed_job doesn't allow unsaved AR objects as arguments ref: delayed_job issue when deserialising arguments we used serializing/deserialising approach for passing params. class PassingData def serialize(data) Base64.encode64(Marshal.dump(data)) end def deserialize(serialized_data) serialized_data = Base64.decode64(serialized_data) Marshal.load serialized_data end end user_details = PassingData.serialize @user where @user = user_data Mailer.delay.order_process("order confirm", user_details) #send mail in background #mailer method def order_process(