所以,我尝试使用我的cron_job任务设置Heroku scheduler,并且在运行heroku run rake weeklydelete时出现以下错误:
Don't know how to build task 'weeklydelete'
我的任务代码如下所示:
task :weeklydelete do
set :output, "#{path}/log/cron.log"
job_type :script, "'#{path}/script/:task' :output"
every :sunday, at: "3:00 AM" do
runner "Event.clear_expired"
runner "Activity.clear_expired"
end
end
基本上,我想删除一周前的活动和活动 - 每个星期天。
我做错了什么?
更新:#lib / tasks / deletion.rb
namespace :deletion do
desc :weekly_delete => :environment do
set :output, "#{path}/log/cron.log"
job_type :script, "'#{path}/script/:task' :output"
every :sunday, at: "3:00 AM" do
runner "Event.clear_expired"
runner "Activity.clear_expired"
end
end
end
并在控制台中调用:
heroku run deletion:weekly_delete -a appname
错误:
Running `rake weekly_delete` attached to terminal... up, run.4492
rake aborted!
Don't know how to build task 'weekly_delete'
答案 0 :(得分:1)
将文件名从deletion.rb更改为deletion.rake
答案 1 :(得分:0)
必须是这样的:
# lib/tasks/deletion.rb
namespace :deletion do
desc :weekly_delete => :environment do
# ...
end
end
你这样称呼它:
$ rake deletion:weekly_delete