当我使用sidekiq时,Pusher没有收到活动

时间:2016-02-24 13:18:13

标签: ruby-on-rails sidekiq pusher

我有一个问题,我无法理解解决方案是什么......

我有一名Sidekiq工作人员

class UsersNotifier
  include Sidekiq::Worker
  require "pusher"

  attr_reader :event, :body, :users_ids, :image_reference

  def perform(event, body, image_reference, users_ids)
    @event = event
    @body = body
    @image_reference = image_reference
    @users_ids = users_ids
    notify_users
  end

  private

  def notify_users
    users_ids.each &method(:notify_user)
  end

  def notify_user(user_id)
    notification = create_notification user_id
    pusher_client["private-#{user_id}"].trigger event, body: body, image: image_reference
  end

  def create_notification(user_id)
    PrivateNotification.create recipient_id: user_id, event: event, body: body, image_reference: image_reference
  end

  def pusher_client
    Pusher::Client.new(
      { 
        app_id: Rails.application.secrets.pusher_app_id,
        key: Rails.application.secrets.pusher_key,
        secret: Rails.application.secrets.pusher_secret
      }
    ) 
  end
end

当我打电话给我的控制器时

    UsersNotifier.perform_async(
      private_notification_params[:event],
      private_notification_params[:body],
      private_notification_params[:image_reference],
      recipients_ids
    )

我的通知存储在数据库中,但我的推送器调试控制台中没有任何消息。

如果我尝试在控制台中调用该工作人员:

UsersNotifier.new.perform(private_notification_params[:event],private_notification_params[:body],private_notification_params[:image_reference],recipients_ids)

一切都很好,我可以在推送控制台中查看事件......

有什么想法吗?

解决方案

我找到了解决办法:我必须重新加载sidekiq工作人员......

0 个答案:

没有答案
相关问题