我正在开发一个多用户树编辑应用程序。它使用 resque gem 进行后台进程。为了避免运行时多用户冲突,我想使用命令模式并将用户操作存储在 resque 队列中,因此如果有人正在删除一个分支,其他用户就无法编辑该分支的子级。
它可以工作,但是第一次从队列中选择作业很慢,因为 resque 工作人员使用 5 秒的间隔检查作业。它显着减慢了编辑界面的速度。可以做这样的事情:
cmd = MyCommand.create!(:attr1 => 'foo', :attr2 => 'bar')
Resque.enqueue(MyCommand, cmd.id)
workers = Resque.workers.select {|w| w.queues.include?('my_queue') }
raise "Should be only one queue for commands!" if workers.size != 1
not_done = true
while not_done
not_done = workers[0].process
end
它可以满足我的需要,但我想知道是否有更优雅的方式来做到这一点。此外, :process 是 Worker 实例不推荐使用的方法。