简体   繁体   English

Rails Cron 作业未针对配置的全局 ruby 版本 MacOS 运行

[英]Rails Cron Job Not running for configured global ruby version MacOS

I am using rbenv to manage multiple ruby versions.我正在使用 rbenv 来管理多个 ruby 版本。 I have the global and shell ruby version set as 2.7.6 .我将全局和 shell ruby 版本设置为2.7.6 I am using rails 7.0.4 .我正在使用rails 7.0.4 My macos version is Monterey 12.5.1 .我的 macos 版本是Monterey 12.5.1 rbenv global also outputs 2.7.6. rbenv global 也输出 2.7.6。

I am using the whenever gem to create a simple cron job.我正在使用whenever gem 创建一个简单的 cron 作业。 My schedule.rb looks like below我的schedule.rb如下所示

set :output, "./log/cron_log.log"

every 1.minute do
  runner "puts 'Hello, world'"
end

but in my crontab log file I am getting this但是在我的 crontab 日志文件中我得到了这个

/Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:54:in `pwd': Operation not permitted - getcwd (Errno::EPERM)
    from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:54:in `lockfile_contents'
    from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:41:in `lockfile_version'
    from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:10:in `bundler_version'
    from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:17:in `block in prioritize!'
    from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:17:in `find_index'
    from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:17:in `prioritize!'
    from /Library/Ruby/Site/2.6.0/rubygems/dependency.rb:282:in `matching_specs'
    from /Library/Ruby/Site/2.6.0/rubygems.rb:257:in `find_spec_for_exe'
    from /Library/Ruby/Site/2.6.0/rubygems.rb:284:in `activate_bin_path'
    from /usr/bin/bundle:23:in `<main>' 

The default shell for my macos version is zsh.我的 macos 版本默认的 shell 是 zsh。 But apparently the crons are run using bash -l -c.但显然 crons 是使用 bash -l -c 运行的。 So I followed the instructions in rbenv's github page and setup.bash_profile like below所以我按照 rbenv 的 github 页面和 setup.bash_profile 中的说明进行操作,如下所示

#.bash_profile
eval "$(rbenv init - bash)"

#.bashrc
source .bash_profile

But I am still getting the same output.Could anybody please help me with this?但我仍然得到相同的 output。有人可以帮我解决这个问题吗?

For everyone facing similar problem on macos, give a try to github.com/rvm/rvm rvm.对于在 macOS 上遇到类似问题的每个人,请尝试 github.com/rvm/rvm rvm。 Switching the ruby version manager to rvm fixed this problem for me.将 ruby 版本管理器切换到 rvm 为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM