Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Sidekiq的提醒通知_Ruby On Rails_Ruby_Angularjs_Sidekiq - Fatal编程技术网

Ruby on rails Sidekiq的提醒通知

Ruby on rails Sidekiq的提醒通知,ruby-on-rails,ruby,angularjs,sidekiq,Ruby On Rails,Ruby,Angularjs,Sidekiq,我是ROR的新手,我使用“Sidekiq”来安排提醒。我可以通过“Sidekiq”成功安排提醒作业/消息。这是“提醒.rb”的代码 class Reminder < ActiveRecord::Base belongs_to :user belongs_to :status_value belongs_to :communication after_create :add_sidekiq_job # before_destroy :remove_sideki

我是ROR的新手,我使用“Sidekiq”来安排提醒。我可以通过“Sidekiq”成功安排提醒作业/消息。这是“提醒.rb”的代码

 class Reminder < ActiveRecord::Base
  belongs_to :user
  belongs_to :status_value 
  belongs_to :communication


   after_create :add_sidekiq_job

  # before_destroy :remove_sidekiq_job

  def add_sidekiq_job
    id = ReminderWorker.perform_at(scheduled_at, {id: self.id.to_s})
    # self.update_attributes(job_id: id)
  end

  def remove_sidekiq_job
    queue =  Sidekiq::ScheduledSet.new
    job = queue.find_job(self.job_id)
    job.delete if job
  end

  def scheduled_at

    self.notification_time.to_time.to_i - Time.now.to_i
  end

end

到目前为止一切都正常,但现在我想在我的通知页面中显示通知消息(我可以从'employer=employer.find(args['id'])中获取)。我怎么能做到

如果您想在用户页面上显示此消息,您应该使用某种持久化的发布/订阅客户端服务器连接,该连接将在sidekiq中提供。在Rails 5中,它可以是,在Rails的早期版本中,或者类似的东西。

在执行操作中,使用来自提醒对象的消息在数据库中创建通知,并从前端检查是否有新的通知。kimrgrey,没有Faya,是否可以这样做?嗯,实现客户机-服务器交互的方法有很多。但若我是对的,你们想把提醒从sidekiq推到订阅用户的页面上,那个么你们需要在sidekiq和浏览器之间建立某种连接。请看一下此屏幕广播:。也许这会澄清一个问题。
class ReminderWorker
  include Sidekiq::Worker

  def perform(args)
    reminder = Reminder.find(args['id'])
    puts "~~~~~Notificaiton~~~~~~~~"
  end
end