avatar

flyctl ssh console 就像 ssh 到虚拟机一样,适合执行一次性脚本。

如果需要定期执行脚本推荐在应用层实现,例如用 sidekiq-cron。

所有回复 1
avatar

谢谢回复

我的脚本内容是:

ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'production'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'rails'
require 'rubygems'

loop do
  Rails.logger.info "== job job, sleep 30 seconds..."
  puts 'hello', '~' * 50
  Test.create(val: 'test')
  sleep 30
end

比如这种,如果在ssh console里面执行ruby hello.rb,每30秒去往Test增加数据,如果console超时了断开了,会中断吗?

sidekiq-cron的话我之后改下,我把任务方法定义好,设置执行时间为30秒,然后直接用fly.io来部署(fly deploy --remote-only)就可以了嘛?

没有更多内容。
@Rei
Ruby 程序员,Ruby China 管理员,GeekNote 创建者。