我试图弄清楚如何让 SuckerPunch 中的后台作业开始工作,而无需加载索引页面。
现在,我要做的是:
$ rails server #在 localhost:3000 启动服务器
然后我转到我的浏览器 URL 并输入 localhost:3000
这会触发我的 SuckerPunch 作业,它们开始运行。
我的 application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
# call job on application start
TestEchoJob.new.async.perform("Download CMS Data")
GetImages.new.async.perform
DeleteImages.new.async.perform
SendLead.new.async.perform
end
这就是我调用作业的地方。我在想也许我可以把它们放在另一个地方,这样我就可以实现我想要的。
在服务器启动时启动作业 - 而不是 http 请求。