Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could try using <a href="http://ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html#method-c-rm_rf" rel="nofollow"><code>FileUtils#rm_rf</code></a> included in the standard library. For example:</p> <pre><code>FileUtils.rm_rf Dir.glob("#{Rails.root}/public/uploads/tmp/*") </code></pre> <p><strong>Edit (to use it with whenever gem)</strong></p> <p>An approach by using a rake task could be:</p> <p>1) Create a rake task in f.ex: <code>lib/tasks/cleanup.rake</code> with something similar to the following:</p> <pre><code>require 'fileutils' namespace :app do desc "Cleanup temp uploads" task :cleanup =&gt; :environment do FileUtils.rm_rf Dir.glob("#{Rails.root}/public/uploads/tmp/*") end end </code></pre> <p>2) In <code>config/schedule.rb</code> (created by whenever after running the wheneverize command):</p> <pre><code>every 5.minutes do # run the previous app:cleanup task rake "app:cleanup" end </code></pre> <p>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:</p> <pre><code>bundle exec whenever -w </code></pre> <p>4) You can check that it worked by typing <code>crontab -l</code> and you should the something like the following:</p> <pre><code># Begin Whenever generated tasks for: /tmp/whene/config/schedule.rb 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /tmp/whene &amp;&amp; RAILS_ENV=production bundle exec rake app:cleanup --silent </code></pre> <p>As a side note, if you want the operation to write some log output, please check <a href="https://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs" rel="nofollow">this page on the whenever github wiki</a>.</p> <p>Hope it helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload