I have installed whenever gem:
I want to clean the directory public/uploads/tmp in my app ruby on rails 3.1 each 5 minutes.
every 5.minutes do
#here go the code for clean the directory tmp
end
How can I do it?
Thank you!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could try using
FileUtils#rm_rfincluded in the standard library. For example:Edit (to use it with whenever gem)
An approach by using a rake task could be:
1) Create a rake task in f.ex:
lib/tasks/cleanup.rakewith something similar to the following:2) In
config/schedule.rb(created by whenever after running the wheneverize command):3) Whenever is only a wrapper to easily define crontab jobs, so now we need to export the defined schedule into the crontab file for the current user. To do that we should type from the application root:
4) You can check that it worked by typing
crontab -land you should the something like the following:As a side note, if you want the operation to write some log output, please check this page on the whenever github wiki.
Hope it helps.