LogofaT
LogofaT

Reputation: 289

Rails whenever not running

I would like to have a task that simply substracts a certain value from my user model at every 5 minutes. My code:

schedule.rb

every 5.minutes do
 runner 'Site::SubstractSomething.execute'
end

app/jobs/SubstractSomething.rb

module Site
 class SubstractSomething
  def initialize
  end

  def execute
   @users = ::User.all
   @users.each { |user| user.update_heat }
  end
 end
end

method inside user model:

  def update_heat
   self.heat -= 10
   self.save
  end

then I ran:

crontab -r 

whenever --update-crontab --set environment='development'

EDIT: I have taken out the job from the namespace and seems that it did the trick.Thanks for the help

Upvotes: 1

Views: 980

Answers (1)

Patru
Patru

Reputation: 4551

You will have to require 'SubstractSomething' in your schedule.rb and make sure that your $LOAD_PATH includes the directory it is situated in. See this question for some possibilities on how to achieve this.

Upvotes: 2

Related Questions