Rails:Rpush'[ERROR] FloatDomainError,Infinity'

时间:2015-01-19 13:23:11

标签: ruby-on-rails ruby gem

我按照确切的步骤从rapns迁移到rpush。 https://github.com/rpush/rpush/wiki/Moving-from-Rapns-to-Rpush

一切似乎都没问题所以我决定在rails控制台中运行这个例子。

n = Rpush::Apns::Notification.new
n.app = Rpush::Apns::App.find_by_name("ios_app")
n.device_token = "..." # 64-character hex string
n.alert = "hi mom!"
n.save!
Rpush.push

我在执行rpush / daemon / apprunner.rb时得到这个堆栈:18

@runners[app_id].enqueue(group) if @runners[app_id]

更准确地说是app_runner.rb:122

batch_size = (notifications.size / num_dispatcher_loops.to_f).ceil

我有与https://github.com/rpush/rpush/wiki/Configuration

相同的配置文件
MacBook-Pro-de-Pierre-2:rails-app pierre$ rails c
Loading development environment (Rails 4.0.12)
2.0.0-p598 :001 > Rpush.push
Rpush::Client::ActiveRecord::App Load (0.3ms) SELECT rpush_apps.* FROM rpush_apps
(0.1ms) BEGIN
Rpush::Client::ActiveRecord::Notification Load (0.4ms) SELECT rpush_notifications.* FROM rpush_notifications WHERE (processing = 0 AND delivered = 0 AND failed = 0 AND (deliver_after IS NULL OR deliver_after < '2015-01-19 11:12:07')) ORDER BY created_at ASC LIMIT 100 FOR UPDATE
SQL (0.3ms) UPDATE rpush_notifications SET processing = 1 WHERE rpush_notifications.id IN (33031)
(21.1ms) COMMIT
[2015-01-19 12:12:07] [ERROR] FloatDomainError, Infinity
/Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/rpush-2.2.0/lib/rpush/daemon/app_runner.rb:117:in ceil' /Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/rpush-2.2.0/lib/rpush/daemon/app_runner.rb:117:inenqueue'
/Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/rpush-2.2.0/lib/rpush/daemon/app_runner.rb:20:in block in enqueue' /Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/rpush-2.2.0/lib/rpush/daemon/app_runner.rb:18:ineach'
/Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/rpush-2.2.0/lib/rpush/daemon/app_runner.rb:18:in enqueue' /Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/rpush-2.2.0/lib/rpush/daemon/feeder.rb:43:inenqueue_notifications'
/Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/rpush-2.2.0/lib/rpush/daemon/feeder.rb:8:in start' /Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/rpush-2.2.0/lib/rpush/push.rb:12:inpush'
(irb):1:in irb_binding' /Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb/workspace.rb:86:ineval'
/Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb/workspace.rb:86:in evaluate' /Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb/context.rb:380:inevaluate'
/Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb.rb:492:in block (2 levels) in eval_input' /Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb.rb:624:insignal_status'
/Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb.rb:489:in block in eval_input' /Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb/ruby-lex.rb:247:inblock (2 levels) in each_top_level_statement'
/Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in loop' /Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb/ruby-lex.rb:233:inblock in each_top_level_statement'
/Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in catch' /Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb/ruby-lex.rb:232:ineach_top_level_statement'
/Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb.rb:488:in eval_input' /Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb.rb:397:inblock in start'
/Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb.rb:396:in catch' /Users/pierrecaserta/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/irb.rb:396:instart'
/Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.0.12/lib/rails/commands/console.rb:90:in start' /Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.0.12/lib/rails/commands/console.rb:9:instart'
/Users/pierrecaserta/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.0.12/lib/rails/commands.rb:62:in <top (required)>' script/rails:6:inrequire'
script/rails:6:in `'
=> {} 
2.0.0-p598 :002 >

更新1 我在app_runner.rb中添加了一些日志:

def enqueue(notifications)
    ap notifications
    ap service
    ap num_dispatcher_loops
    if service.batch_deliveries?
      batch_size = (notifications.size / num_dispatcher_loops.to_f).ceil
      notifications.in_groups_of(batch_size, false).each do |batch_notifications|
        batch = Batch.new(batch_notifications)
        queue.push(QueuePayload.new(batch))
      end
    else
      batch = Batch.new(notifications)
      notifications.each do |notification|
        queue.push(QueuePayload.new(batch, notification))
        reflect(:notification_enqueued, notification)
      end
    end
  end

以下是日志:

    2.0.0-p598 :006 > Rpush.push
    [
    [0] #<Rpush::Client::ActiveRecord::Apns::Notification:0x007fba30939ad0> {

    :id => 33040,
    :badge => nil,
    :device_token => "d1e4c1c....50",
    :sound => "default",
    :alert => "hi mom! TESTTEST8",
    :data => nil,
    :expiry => 86400,
    :delivered => false,
    :delivered_at => nil,
    :failed => false,
    :failed_at => nil,
    :error_code => nil,
    :error_description => nil,
    :deliver_after => nil,
    :created_at => Mon, 19 Jan 2015 16:07:10 CET +01:00,
    :updated_at => Mon, 19 Jan 2015 16:07:10 CET +01:00,
    :alert_is_json => false,
    :type => "Rpush::Client::ActiveRecord::Apns::Notification",
    :collapse_key => nil,
    :delay_while_idle => false,
    :registration_ids => nil,
    :app_id => 1,
    :retries => 0,
    :uri => nil,
    :fail_after => nil,
    :processing => true,
    :priority => nil,
    :url_args => nil,
    :category => nil
    }
    ]
    Rpush::Daemon::Apns
    0

[2015-01-19 16:07:13] [错误] FloatDomainError,Infinity

1 个答案:

答案 0 :(得分:1)

在红宝石中除以零会给你无限:

irb(main):002:0> 4 / 0.to_f
=> Infinity

在这种情况下,您的调试显示num_dispatcher_loops为0.围绕代码(rpush/daemon/app_runner.rb),这是@dispatcher_loops的长度,它被初始化为空但填充在{{ 1}}。我的猜测是后者没有被调用。它应该在#start_dispatchers中发生。追溯(仅在代码库中搜索)会导致回到.start_appDaemon以及Embed上的顶级方法。 Synchronizer可能实际上并未正常运行。

您使用什么方法(来自README中的“运行Rpush”)来运行rpush?