0

i am new in rails, i need to run one task in rails, that means have one function, which needs to call with in a 5 minutes of time interval? Because i am working with a prototype, and its running on heroku, i couldn't run any paid addons with heroku, also i read that, heroku have one scheduler, its free, but that only work with a 10 minutes interval of time. so i am thinking of, run a thread for this prototype project, ie

here writing one thread, that needs to call a function after a 5 minutes sleep? also how can i run that thread when starting the rails server? can i start that thread and server via the proc file? is this the correct way to do this?

def test

end
t = Thread.new do
  while true do
  sleep 60
    test()       
  end
end
t.join

1 Answers1

0

In my opinion you should use some cronjob gem like whenever

This gem will create a file in config/schedule.rb. Using this file you can call any rake task, run commands or even can call methods of classes.

For example:

every 10.minutes do
   # run rake task or call some class's method
end

But if you insist not using cronjob related gem then you should use some gem like foreman

It's easy to use. you can learn it from this blog or this railscast

EDIT:

This SO question might help you further...

LATEST EDIT:

Yes it's possible see here. It suggest using this add-ons and it's free :)

Community
  • 1
  • 1
Hardik
  • 3,815
  • 3
  • 35
  • 45