【发布时间】:2019-10-23 18:29:25
【问题描述】:
我将我的 cron 任务放在一个模块中,然后放在我的 Sinatra 服务器中。
module Cron
scheduler = Rufus::Scheduler.new
scheduler.every "30m", :first => :now do
run_cmd('git pull')
puts "pulled the repo!!!"
end
end
class MyServer < Sinatra::Base
include Cron
end
应用程序的入口点是独角兽(unicorn config/config.ru -p 9393 -c config/unicorn.rb),在unicorn.rb 中,有这一行
worker_processes 7
因此,git pull 每 30 分钟运行七次,pulled the repo!!! 被打印七次。
有没有办法只在一个线程中运行这个任务?我尝试将其放在worker_processes 7 行上方的 unicorn.rb 中,但我不确定这是否是此代码所在的最佳位置。
【问题讨论】: