Anton
Anton

Reputation: 87

How to make code run every 30 minutes?

I have this code in home controller

  def index
    urls = RssStream.select("rss_streams.url").all.map { |v| v[:url] }
    RssStream.update_all_feeds(urls)
  end

And I want to make run this code every 30.minutes. How can I do it?

I've tried through gem 'whenever', nothing happens

Upvotes: 0

Views: 1548

Answers (3)

Deepika
Deepika

Reputation: 826

Write a script for the code and schedule a cron job of 30 mins. You can use webmin for this. Link for ref:- http://www.hosting.com/support/webmin/create-new-cron-jobs-using-the-webmin-interface or http://railscasts.com/episodes/164-cron-in-ruby

Upvotes: 1

Migol
Migol

Reputation: 8447

You should put it into Rake task and probably use cron job to execute it.

Upvotes: 0

csch
csch

Reputation: 4846

This code should not be placed in your controller. Extract it into an own Rake task and let that one be executed by whenever!

Upvotes: 3

Related Questions