有没有人有使用aws opsworks上的每当宝石的经验/成功?有一个好的食谱?我可以将该配方放在单独的图层上并将一个实例与该附加图层关联吗?还是有更好的方法来做到这一点?谢谢!!!每当aws opsworks上的宝石
编辑:
我们最终做不同的有点......
代码:
真的不能发布真正的代码,但它是这样的:在
deploy/before_migrate.rb:
[:schedule].each do |config_name|
Chef::Log.info("Processing config for #{config_name}")
begin
template "#{release_path}/config/#{config_name}.rb" do |_config_file|
variables(
config_name => node[:deploy][:APP_NAME][:config_files][config_name]
)
local true
source "#{release_path}/config/#{config_name}.rb.erb"
end
rescue => e
Chef::Log.error e
raise "Error processing config for #{config_name}: #{e}"
end
end
in deploy/after_restart.rb:
execute 'start whenever' do
cwd release_path
user node[:deploy][:APP_NAME][:user] || 'deploy'
command 'bundle exec whenever -i APP_NAME'
end
在配置/ schedule.rb.erb:
<% schedule = @schedule || {} %>
set :job_template, "bash -l -c 'export PATH=/usr/local/bin:${PATH} && :job'"
job_type :runner, 'cd :path && bundle exec rails runner -e :environment ":task" :output'
job_type :five_runner, 'cd :path && timeout 300 bundle exec rails runner -e :environment ":task" :output'
set :output, 'log/five_minute_job.log'
every 5.minutes, at: <%= schedule[:five_minute_job_minute] || 0 %> do
five_runner 'Model.method'
end
最后我们处理这个如下: 添加值在堆栈json中指定每当cron运行哪个主机,并且默认为rails_app1 在只在该主机上运行的rails项目中有一个部署挂钩。 这将cron放在第一台主机或我们指定的任何一个上,并且很容易配置和管理。 我们还有一个erb文件,它被计算为schedule.rb,以便我们可以设置各种参数,例如每天运行的时间或每小时运行一分钟的时间。这个erb文件也在部署钩子中进行评估。 – nroose
如果可能,请你分享一下代码吗? – jwako
是的请选择,一些更详细的建议会很棒。 –