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 my Worker
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
To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.
Configuring SidekiqThe server is the sidekiq process which pulls jobs from Redis. That means when deploying, our web dynos in Heroku will use a max of size number of connections to push jobs to Redis, no matter how many threads they have.
Sidekiq server process pulls jobs from the queue in Redis and processes them. Like your web processes, Sidekiq boots Rails so your jobs and workers have the full Rails API, including Active Record, available for use. The server will instantiate the worker and call perform with the given arguments.
Sidekiq is an open source job scheduler written in Ruby. It's important to be aware that Sidekiq by default doesn't do scheduling, it only executes jobs. The Enterprise version comes with scheduling out of the box.
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 ;).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With