捆绑器:不可执行:bin/rails 在 rails 生产中使用时 gem
bundler: not executable: bin/rails in rails production while using whenever gem
每当 gem 用于 rails 应用程序中的 cronjobs - 生产。
我遇到错误 bundler: not executable: bin/rails
scheduler.rb
every 15.minute do
runner 'TestJob.perform_later()'
end
定时任务
0,15,30,45 * * * * /bin/bash -l -c 'cd /home/deploy/my-app/releases/20190719103116 && bundle exec bin/rails runner -e production '\''TestJob.perform_later()'\'''
但是当我 运行 /bin/bash -l -c 'cd /home/deploy/my-app/releases/20190719103116 && bundle exec bin/rails runner -e production '\''TestJob.perform_later()'\'''
在我的 bash 中用 rails
替换 bin/rails
时 fine.How 可以解决这个问题吗?
通过抽取任务尝试运行:
config/schedule.rb
every 15.minutes do
rake 'testing:run_tests'
end
lib/tasks/testing.rake
namespace :testing do
desc 'Run tests'
task run_tests: :environment do
TestJob.perform_later
end
end
快速解答
为了继续使用原来的 runner
工作类型,只需将其添加到您的 schedule.rb:
set :runner_command, "rails runner"
长答案
文档对此不是很清楚,但您可以在 /lib/whenever/setup.rb:
中看到默认的 runner
作业类型被设置为这样
job_type :runner, "cd :path && :bundle_command :runner_command -e :environment ':task' :output"
在同一文件中,您可以看到此 :runner_command
设置设置为:
set :runner_command, case
when Whenever.bin_rails?
"bin/rails runner"
when Whenever.script_rails?
"script/rails runner"
else
"script/runner"
end
所以默认情况下,您的 cron 命令将使用 bin/rails runner
创建,除非您用上述答案覆盖它。
每当 gem 用于 rails 应用程序中的 cronjobs - 生产。
我遇到错误 bundler: not executable: bin/rails
scheduler.rb
every 15.minute do
runner 'TestJob.perform_later()'
end
定时任务
0,15,30,45 * * * * /bin/bash -l -c 'cd /home/deploy/my-app/releases/20190719103116 && bundle exec bin/rails runner -e production '\''TestJob.perform_later()'\'''
但是当我 运行 /bin/bash -l -c 'cd /home/deploy/my-app/releases/20190719103116 && bundle exec bin/rails runner -e production '\''TestJob.perform_later()'\'''
在我的 bash 中用 rails
替换 bin/rails
时 fine.How 可以解决这个问题吗?
通过抽取任务尝试运行:
config/schedule.rb
every 15.minutes do
rake 'testing:run_tests'
end
lib/tasks/testing.rake
namespace :testing do
desc 'Run tests'
task run_tests: :environment do
TestJob.perform_later
end
end
快速解答
为了继续使用原来的 runner
工作类型,只需将其添加到您的 schedule.rb:
set :runner_command, "rails runner"
长答案
文档对此不是很清楚,但您可以在 /lib/whenever/setup.rb:
中看到默认的runner
作业类型被设置为这样
job_type :runner, "cd :path && :bundle_command :runner_command -e :environment ':task' :output"
在同一文件中,您可以看到此 :runner_command
设置设置为:
set :runner_command, case
when Whenever.bin_rails?
"bin/rails runner"
when Whenever.script_rails?
"script/rails runner"
else
"script/runner"
end
所以默认情况下,您的 cron 命令将使用 bin/rails runner
创建,除非您用上述答案覆盖它。