Sidekiq 工人没有工作
Sidekiq worker didn't work
我尝试设置一个基本的通知工作者来通知某些用户。
但在我的示例中,我的用户没有收到任何通知。
我尝试执行 worker 的控制器操作:
def index
NotificationWorker.delay().perform(current_user.id, 'error', 'refresh', 'test', 'asd')
# ActionCable.server.broadcast "web_notifications_#{current_user.id}", { type: 'error', icon: 'refresh', title: 'title', body: 'body' }
end
我的notification_worker.rb
class NotificationWorker
include Sidekiq::Worker
def perform(user_id, type, icon, title, body)
Notification.create(user_id, type, icon, title, body)
end
end
和我的通知模型:
class Notification < ActiveRecord::Base
# belongs_to
belongs_to :users
def self.create(user_id, type, icon, title, body)
ActionCable.server.broadcast "web_notifications_#{user_id}", { type: 'error', icon: 'refresh', title: 'title', body: 'body' }
end
end
当我使用这个
Notification.create(current_user.id, 'error', 'refresh', 'test', 'asd')
我的用户收到了通知,但我不想用 sidekiq 发送给他们
根据我在评论中的假设 - 问题是你没有 运行 sidekiq。
我尝试设置一个基本的通知工作者来通知某些用户。 但在我的示例中,我的用户没有收到任何通知。
我尝试执行 worker 的控制器操作:
def index
NotificationWorker.delay().perform(current_user.id, 'error', 'refresh', 'test', 'asd')
# ActionCable.server.broadcast "web_notifications_#{current_user.id}", { type: 'error', icon: 'refresh', title: 'title', body: 'body' }
end
我的notification_worker.rb
class NotificationWorker
include Sidekiq::Worker
def perform(user_id, type, icon, title, body)
Notification.create(user_id, type, icon, title, body)
end
end
和我的通知模型:
class Notification < ActiveRecord::Base
# belongs_to
belongs_to :users
def self.create(user_id, type, icon, title, body)
ActionCable.server.broadcast "web_notifications_#{user_id}", { type: 'error', icon: 'refresh', title: 'title', body: 'body' }
end
end
当我使用这个
Notification.create(current_user.id, 'error', 'refresh', 'test', 'asd')
我的用户收到了通知,但我不想用 sidekiq 发送给他们
根据我在评论中的假设 - 问题是你没有 运行 sidekiq。