Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:54:14+00:00 2026-05-30T23:54:14+00:00

I have installed whenever gem : I want to clean the directory public/uploads/tmp in

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:54:15+00:00Added an answer on May 30, 2026 at 11:54 pm

    You could try using FileUtils#rm_rf included in the standard library. For example:

    FileUtils.rm_rf Dir.glob("#{Rails.root}/public/uploads/tmp/*")
    

    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.rake with something similar to the following:

    require 'fileutils'
    
    namespace :app do
      desc "Cleanup temp uploads"
      task :cleanup => :environment do
        FileUtils.rm_rf Dir.glob("#{Rails.root}/public/uploads/tmp/*")
      end
    end
    

    2) In config/schedule.rb (created by whenever after running the wheneverize command):

    every 5.minutes do 
      # run the previous app:cleanup task
      rake "app:cleanup"
    end
    

    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:

    bundle exec whenever -w
    

    4) You can check that it worked by typing crontab -l and you should the something like the following:

    # 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 && RAILS_ENV=production bundle exec rake app:cleanup --silent
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fresh Ubuntu install with ruby -v 1.9.2, rails -v 3.1.1, gem
I have installed ruby193 and I've installed rails via the command prompt. However, whenever
I have downloaded the appinventor_extras_setup.exe from net and installed the complete package. But whenever
I have both ruby 1.8.7 and 1.9.2 installed on my system. I have a
I have blend 4 installed and whenever I create a WPF 4 project and
I have installed Jenkins executable on OSX, but now I want to stop it
I have the following gemfile: source 'http://rubygems.org' source 'http://gems.engineyard.com' gem 'rails', '~> 3.1.0.rc4' gem
I have a custom Ruby library directory that I'd like to have automatically added
i have eclipse installed with tomcat 7. whenever i run my webapp, tomcat deletes
I have PIL installed, however whenever I try to upload a .png file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.