Skip to content

Instantly share code, notes, and snippets.

@stanmx
Last active December 27, 2015 10:19
Show Gist options
  • Save stanmx/7310350 to your computer and use it in GitHub Desktop.
Save stanmx/7310350 to your computer and use it in GitHub Desktop.
whenever gem implementation
Following the instructions from @lol007 http://stackoverflow.com/a/18864911/556548 i make the next example:
I haved a CRUD with info called Post with title:string, content:text and status:boolean with Ruby 1.8.7 and Rails 3.2.11 in development environment.
I'm add whenever gem to my gemfile and run the bundle install command. Then i run the command whenever . in the console.
This generate the config/schedule.rb when i add the next code:
# schedule.rb
every 5.minutes do
runner "Post.check_updated_at"
end
Then in my models/post.rb
# post.rb
def self.check_updated_at
where('updated_at > ?', 30.minutes.ago).update_all({ :status => :true })
end
I run the command rails s in the console. and wait 5 minutes to see if something happend but not, still the status like i created and updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment