Rail app on Heroku: How to implement a "scheduled job" at regular intervals -
i not sure if question of correct format so.
i have rails app deployment on heroku. in development using "crono" gem send simple email out every week remind users of various things. can see how use in production heroku. there nothing on in google search. therefore question is: "what best way implement simple weekly job in rails app deployed on heroku. heroku has "scheduler" "best effort" add on can claim reliable (according documentation)
thanks
there's 2 ways achieve want:
1. use heroku scheduler (i would)
honestly it's simple set up, use this. it's extremely cheap because pay dyno while job running. after it's run heroku destroys dyno (it's 1 off dyno)
the best way implement have background jobs callable rake task, , have scheduler call that.
if have time interval heroku doesn't support, handle in code. example if want send e-mails once week, have timestamp record when last email sent. run scheduler once day , check see if it's ok send email, if not nothing.
2. use kind of scheduler gem
there's bunch of them out there. example, rufus.
in case, you'd write rufus jobs. need have worker dyno running rufus, more expensive.
you'd tell dyno run rufus , keep running rufus specifying command rufus needs in procfile. like:
scheduler: rake rufus:scheduler # add rake task rufus scheduler process
(credit above snippet how avoid rufus scheduler being called many times there no.of dynos?)
Comments
Post a Comment