[Rails] 執行Whenever任務時的”invalid byte sequence in US-ASCII (ArgumentError)”錯誤

Dosmanthus
Feb 24, 2017 · 2 min read

錯誤1:
部署上AWS後Whenever沒有正確執行,於是連線上server app 根目錄執行 $ whenever 出現 “invalid byte sequence in US-ASCII (ArgumentError)"的錯誤。

解決方式:
修改AWS端/etc/environment內的區域設置

LANG=en_US.utf-8
LC_ALL=en_US.utf-8

執行

$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8

Update crontab

$ bundle exec whenever --update-crontab
$ crontab -l

就可正確列出 schedule.rb中的任務。

錯誤2:
解決以上錯誤後crontab還是未正確執行,查詢log/cron.log後顯示bundle: command not found

解決方式:
在schedule.rb file的頂部加上

env :PATH, ENV['PATH']
env :GEM_PATH, ENV['GEM_PATH']# 如果出現Could not find rake" 錯誤需加上此行

完成後可正確執行。

參考資料:
-
stackoverflow
- Hatena blog

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade