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
NotificationWorker.delay().perform, doNotificationWorker.perform_async- Mike PerhamNotificationWorker.perform_asyncand notNotificationWorker.delay().perform? - Evolutiodelays intended usage. Please read the docs. github.com/mperham/sidekiq/wiki/The-Basics#client Delay is for calling class methods on classes. github.com/mperham/sidekiq/wiki/… - Mike Perham