a year ago
I have a rails application with a rake file that I need to run once a week. I see the setting for cron job but no where to tell it what file to use.
The rake file does some postgres management
namespace :products do
desc "Reset seed products and archive old products"
task reset: :environment do
begin
puts "Starting product reset..."
seed_sql = File.read(Rails.root.join('db', 'seed_products.sql'))
ActiveRecord::Base.connection.execute(seed_sql)
Product.where(is_seed_data: false)
.where('created_at < ?', 7.days.ago)
.update_all(status: 'archived')
puts "Product reset completed!"
ensure
ActiveRecord::Base.connection_pool.disconnect!
end
end
end
3 Replies
a year ago
You'll probably want to set it in the start command? https://docs.railway.com/guides/start-command
Status changed to Awaiting User Response Railway • over 1 year ago
a year ago
Sorry, I am new to your platform and running a cron job and could not figure out your documentation. The file rake file and the sql file that is needs to run is in my rails application which is already running.
This is not a file that runs a the start of an application but rather one that runs once a week to reset some of the data in my connected postgres db.
Do I need to make it a separate service in my project verses having it in the rails application?
If someone can please give me detailed steps or jump on a quick call to help me that would be great.
Status changed to Awaiting Railway Response Railway • over 1 year ago
a year ago
Yup you'll want to create a separate service with a start command that's your rake command
Then set the cron syntax in the service settings to be "Once per week"
Status changed to Awaiting User Response Railway • over 1 year ago
Status changed to Solved jake • over 1 year ago