Scheduling tasks to run on heroku - How does it work in detail?

50 views Asked by At

I have depoloyed to heroku a project where Im using node-schedule, wehre a job is supose to run every 20 min. Ive been reading about heroku dynos and advance schedule and I find it still confusing, so if someone could answer my questions, it would be very much appreciated!!

"free version of Heroku the server sleeps after 30 mins of inactivity"

  1. I am using heroku eco, is it the same then as with the free version?
  2. It says every 30 min. The job is scheduled with my code every 20 min. Shouldnt it then still run as there qouldnt be 30 min of inactivity?
  3. I dont fully understand dynos. Could someone please explain them- do I need them in case of a cron job/node-schedule?
  4. I have "750 free dynos". How does that work? Every time the scheduled task is executed a free dyno is used?!

Without fully understand what I exactly need, I have followed a tutorial for scheduled tasks deployed to heroku :

const schedule = require('node-schedule');
schedule.scheduleJob('*/15 * * * *', ()=>{
    // Execute something every 15 minutes
});

created Procfile with

clock:  node schedule.js

Then I created a folder named lib/tasks/ and added a schedule.rake file with the following:

desc "Pings PING_URL to keep a dyno alive"
task :dyno_ping do
  require "net/http"
  if ENV['PING_URL']
    uri = URI(ENV['PING_URL'])
    Net::HTTP.get_response(uri)
  end
end

then I deployed and then

$ heroku config:add PING_URL=http://Procfile.herokuapp.com
$ heroku addons:add scheduler:standard
$ heroku addons:open scheduler

then I choose to run it every 10 min with the following command added to heroku: rake dyno_ping

Now I am also wondering how/how many dynos will I loose every 10 min? And how it works. That the task is run every 10 min, means the app deployed to heroku will be prevented from 'sleeping' and thus executing the job as I specified (which is every 20 min)?

0

There are 0 answers