I tried to setup a basic notification worker to notify some user. But in my example my user didn't get any notifcation.
my controller action where I tried to perform my 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
my 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
and my notification model:
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
when I use this
Notification.create(current_user.id, 'error', 'refresh', 'test', 'asd')
my user get the notification but I wan't to send them with sidekiq
As per my assumption in comments - the issue was that you did not run the sidekiq.