Pass Object to Sidekiq
12,464
Best way to approach the problem you are trying to solve is to save the object data in a database and then pass the id of @mixpanel
to your MixpanelWorker
job like so:
@mixpanel = Mixpanel.create [your parameters]
MixpanelWorker.perform_async @mixpanel.id, 'person', mixpanel_distinct_id, cleaned_params
Then your MixpanelWorker
would handle the job like this:
def perform(mixpanel_id, type_of_send, distinct_id, event)
mixpanel_object = Mixpanel.find mixpanel_id
case type_of_send
when 'person'
mixpanel_object.people.set(distinct_id, event)
when 'event'
mixpanel_object.track(distinct_id, event)
end
end
Also read the link that Mike Perham posted, I think he may know a little about Sidekiq ;).
Author by
Elijah Murray
Updated on August 16, 2022Comments
-
Elijah Murray over 1 year
I tried passing an small object to
sidekiq
, but it converts it to a hash. This object is a tracking object for mixpanel. I also tried accessing session variables in myWorker
but they aren't available there either.Thoughts?
Controller
MixpanelWorker.perform_async(@mixpanel, 'person', mixpanel_distinct_id, cleaned_params)
MixpanelWorker
def perform(mixpanel_object, type_of_send, distinct_id, event) case type_of_send when 'person' mixpanel_object.people.set(distinct_id, event) when 'event' mixpanel_object.track(distinct_id, event) end end