js_beginner
js_beginner

Reputation: 95

how to use Whenever gem properly

I am just trying to create a record every 5 minutes using whenever gem but it doesn't create anything on the production.

config/schedule.rb

every 5.minutes do 
 runner "Post.new_post"
end

lib/tasks/post.rb

class Post
  def new_post
    Post.create(title: "cron testing")
  end
end

and I ran whenever command then pushed to the live server but It doesn't create any records on the production.

Which steps did I miss?

Upvotes: 1

Views: 732

Answers (1)

Yurii
Yurii

Reputation: 691

I'm assuming that you're using rails, so — files placed in lib/tasks are loaded as custom rake tasks by default, you can check it here.

Brief instruction:

  • Run rails generate task posts create_post
  • Modify lib/tasks/posts.rake
  • Update config/schedule.rb from runner "Post.new_post" to rake 'posts:create_post'
  • Run whenever --update-crontab somehow on the server ;)

Upvotes: 1

Related Questions