【问题标题】:bundler: not executable: bin/rails in rails production while using whenever gem捆绑器:不可执行:无论何时使用 gem,rails 生产中的 bin/rails
【发布时间】:2019-07-19 10:52:51
【问题描述】:

我在 Rails 应用程序中将 gem 用于 cronjobs - 生产。 我收到一个错误bundler: not executable: bin/rails

scheduler.rb

every 15.minute do
 runner 'TestJob.perform_later()'
end

crontab

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()'\'''

但是当我在我的 bash 中运行 /bin/bash -l -c 'cd /home/deploy/my-app/releases/20190719103116 && bundle exec bin/rails runner -e production '\''TestJob.perform_later()'\''' 时,将 bin/rails 替换为 rails 这工作正常。如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails whenever whenever-capistrano


    【解决方案1】:

    尝试通过 rake 任务运行它:

    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
    

    【讨论】:

    【解决方案2】:

    快速解答

    为了仍然使用原来的 runner 作业类型,只需将其添加到您的 schedule.rb

    set :runner_command, "rails runner"
    

    长答案

    文档对此不是很清楚,但您可以看到默认的 runner 作业类型设置为无论何时的 /lib/whenever/setup.rb

    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 创建,除非您使用上述答案覆盖它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 1970-01-01
      • 2012-06-10
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多