Search code examples
ruby-on-railsrubyruby-on-rails-4rakewhenever

rake task has to run a controller method every 2 minutes


The rake task has to run a method (index) in downloads_controller every 2 minutes. so i installed whenever gem. and in "config/schedule.rb" file i added.

every 2.minutes do
 rake "*****"                 
end

I don't know how to give my action(app/controller/downloads_controller.rb->index)directory after rake.is there anything has to modify in other files? anyone please help me.

updated code

every 1.minutes do
  rake "Download.index"
end

and moved index method to Download model. and how to check whether rake task working or not?


Solution

  • now its working for me....

    i moved method implementation to "downloader.rake" file which added at lib/tasks. the code in downloader.rake is

    namespace :downloader do
    desc "download a file"
    task:downloading => :environment do
    Rails.logger.info("message from task")
    .......method implementation........
    end
    end
    

    i scheduled the above implementation in "schedule.rb" in config file

    every 2.minutes do
    rake "downloader:downloading"
    end
    

    here "downloader" is the name of the rake file and "downloading" is the task name