I am using delayed_job to do some background task. In between I want to track some events. I am using mixpanel gem to track the events. In controller its working perfectly fine. But not in Delayed Job.
Code I am using
@original_message = Message.find(message_id)
@mixpanel= Mixpanel::Tracker.new("43242637426346287482", message_id, true)
@mixpanel.track_event("blank_body", {:reset_result => "sucess" })
//message_id is a unique for every request.
I have specified
gem 'mixpanel' in gemfile
{undefined method `[]=' for 45:Fixnum
/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/mixpanel-0.9.0/lib/mixpanel/tracker.rb:38:in clear_queue'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/mixpanel-0.9.0/lib/mixpanel/tracker.rb:13:in
initialize'\n/Users/mohit/projects/textadda/lib/message_job.rb:109:in new'\n/Users/mohit/projects/textadda/lib/message_job.rb:109:in
perform'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/backend/base.rb:87:in invoke_job'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:120:in
run'\n/Users/mohit/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/timeout.rb:67:in timeout'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:120:in
run'\n/Users/mohit/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/benchmark.rb:308:in realtime'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:119:in
run'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:177:in reserve_and_run_one_job'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:104:in
work_off'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:103:in times'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:103:in
work_off'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:78:in start'\n/Users/mohit/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/benchmark.rb:308:in
realtime'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:77:in start'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:74:in
loop'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:74:in start'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/tasks.rb:9\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:205:in
call'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:205:in execute'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:200:in
each'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:200:in execute'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:158:in
invoke_with_call_chain'\n/Users/mohit/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/monitor.rb:242:in synchronize'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:151:in
invoke_with_call_chain'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:144:in invoke'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:112:in
invoke_task'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:90:in top_level'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:90:in
each'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:90:in top_level'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:129:in
standard_exception_handling'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:84:in top_level'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:62:in
run'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:129:in standard_exception_handling'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:59:in
run'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/bin/rake:32\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/bin/rake:19:in `load'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/bin/rake:19
EDIT
I have implemented mixpanel in background process using standard get request. But I am still looking for the solution how can I use Mixpanel gem in background process.
require 'mixpanel'
to explicitly require it before you call it viaMixpanel::Tracker...
? – iwasrobbed