如何让 gem 在我的 Rails 应用程序上工作?

问题描述 投票:0回答:1

我目前正在创建一个“习惯跟踪器”应用程序,并希望每天创建我的模型 Day 的一个实例。我尝试在我的应用程序上每当 gem 时实现 de ,但它似乎不起作用;我已经在线学习了每一个教程(这里,youtube,...),从头开始重新启动该过程...什么也没有。 这是我的代码:

时间表.rb

every 3.minute do
  command "cd /Users/myusername/code/myusername/habit-tracker && bundle exec rails runner 'Day.create!'"
end

set :environment, "development"


# every 1.minute do
#   command "bundle exec rails runner Day.create!"
#   rake 'batch:create_day', environment: "development"
#   runner 'Day.create!', environment: "development"
# end

# every :minute do
#   command "bundle exec rails runner Day.create!"
#   rake 'batch:create_day', environment: "development"
#   runner 'Day.create!', environment: "development"
# end

批次.rake

namespace :batch do
  desc "Create a new instance of Day everyday"
  task create_day: :environment do
    Day.create!
  end
end

反对-l

# Begin Whenever generated tasks for: /Users/myusername/code/myusername/habit-tracker/config/schedule.rb at: 2024-04-30 17:17:19 +0200
0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /bin/bash -l -c 'cd /Users/myusername/code/myusername/habit-tracker && bundle exec rails runner '\''Day.create!'\'''

# End Whenever generated tasks for: /Users/myusername/code/myusername/habit-tracker/config/schedule.rb at: 2024-04-30 17:17:19 +0200

我已经在线学习了每一个教程(这里,youtube,...),从头开始重新启动该过程......什么也没有。

ruby-on-rails rubygems whenever
1个回答
0
投票

首先确保 cron 正在运行

sudo service cron status

您是否运行过以下命令将计划文件的内容添加到 crontab 中?

whenever --update-crontab
crontab -r

要查看输出,您可以将以下行添加到schedule.rb

set :output, './log/example.log'

确保再次运行

whenever --update-crontab
crontab -r
© www.soinside.com 2019 - 2024. All rights reserved.