在延迟工作中无法击中mixpanel?

时间:2011-08-01 14:13:11

标签: ruby-on-rails ruby-on-rails-3 delayed-job mixpanel

我正在使用delayed_job来完成一些后台任务。在我之间我想跟踪一些事件。我正在使用mixpanel gem来跟踪事件。在控制器中它的工作非常好。但不是在延迟工作中。

我正在使用的代码

@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.

我指定了

  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初始化'\ n / Users / mohit / projects / textadda / lib / message_job.rb:109:在new'\n/Users/mohit/projects/textadda/lib/message_job.rb:109:in执行'\ n / Users / mohit / .rvm / gems / ruby​​-1.8.7-p334 / gems / delayed_job-2.1。 4 / lib / delayed / backend / base.rb:87:在invoke_job'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:120:in运行'\ n / Users / mohit / .rvm / rubies / ruby​​-1.8.7-p334 / lib / ruby​​ / 1.8 / timeout。 rb:67:在timeout'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:120:in运行'\ n / Users / mohit / .rvm / rubies / ruby​​-1.8.7-p334 / lib / ruby​​ / 1.8 / benchmark.:30:realtime'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:119:in运行'\ 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:在start'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/delayed_job-2.1.4/lib/delayed/worker.rb:74:in循环'\ 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 / ge ms / ruby​​-1.8.7-p334 / gems / rake-0.9.2 / lib / rake / task.rb:205:在execute'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:200:in每个'\ 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:在top_level'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:90:in每个'\ n / Users / mohit / .rvm / gems / ruby​​-1.8.7-p334 / gems / rake-0.9.2 / lib / rake / application.rb: 90:在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 { {1}}运行'\ n / Users / mohit / .rvm / gems / ruby​​-1.8.7-p334 / gems / rake-0.9.2 / lib / rake / application.rb:129:in top_level'\n/Users/mohit/.rvm/gems/ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:62:in运行'\ N /用户/莫希特/ .rvm /宝石/红宝石1.8.7-P334 /宝石/耙0.9.2 / bin中/耙:32 \ N /用户/莫希特/ .rvm /宝石/红宝石-1.8 .7-p334 / bin / rake:19:在'load'\ n / Users / mohit / .rvm / gems / ruby​​-1.8.7-p334 / bin / rake:19

修改

我使用标准的get请求在后台进程中实现了mixpanel。但我仍然在寻找解决方案,如何在后台进程中使用Mixpanel gem。

2 个答案:

答案 0 :(得分:1)

注意:此答案截至2012年10月15日为止,因为初始化方法不再采用ENV参数

https://github.com/zevarito/mixpanel Mixpanel::Tracker.new上的示例被调用如下:

Mixpanel::Tracker.new("YOUR_MIXPANEL_API_TOKEN", request.env, true)

在控制器上下文中,request.env是一个哈希值。

在您上面的代码中传递message_id作为第二个参数,它看起来像一个整数。对不起,不能再帮忙了,对mixpanel gem一无所知,但那是你问题的根源。

如果mixpanel API文档告诉您可以传递一个整数作为第二个参数,那么它是不正确的。以下是与https://github.com/zevarito/mixpanel/blob/master/lib/mixpanel/tracker.rb

中的错误相关的代码
module Mixpanel
  class Tracker
    def initialize(token, env, async = false)
      @token = token
      @env = env
      @async = async
      clear_queue
    end

# snip

    def clear_queue
      @env["mixpanel_events"] = []
    end

# snip

  end
end

将一个整数作为第二个参数传递给初始化程序将不起作用,因为Fixnum类没有散列赋值([]=)方法,这正是您获得的错误消息

如果文档告诉您这可能是一个整数,那么您应该针对mixpanel提出问题。

答案 1 :(得分:1)

你应该做这样的事情:

@mixpanel= Mixpanel::Tracker.new("43242637426346287482", {:REMOTE_ADDR => message_id}, true)
@mixpanel.track_event("blank_body", {:reset_result => "sucess" })

gem期望第二个变量是请求环境,因此将以这种方式获取ip地址,并将其发送到mixpanel.com。但我甚至不确定这是否真的需要,所以我认为即使是简单的

@mixpanel= Mixpanel::Tracker.new("43242637426346287482", {}, true)
@mixpanel.track_event("blank_body", {:reset_result => "sucess" })

应该有用。

希望这有帮助。