This add-on is operated by MISC CO
Reliable and powerful task scheduling as a service.
Last updated 25 July 2019
The Advanced Scheduler add-on is currently in beta.
Table of Contents
Advanced Scheduler is an add-on that provides task scheduling as a service.
The service is built on the same principles as Heroku Scheduler, and it distinguishes itself by providing greater flexibility, transparency, and reliability in a cost-effective way.
All features are accessible from the Advanced Scheduler dashboard. It allows you to configure triggers that execute your tasks once on a specific date and time, or at a certain time interval. When executed, these tasks run in one-off dynos and show up in your logs. This service is language-agnostic, meaning it can be integrated regardless of the programming language you use.
Provisioning the add-on
Advanced Scheduler can be attached to a Heroku application via the CLI:
A list of all plans available can be found here.
$ heroku addons:create advanced-scheduler -----> Adding advanced-scheduler to sharp-mountain-4005... done, v18 (free)
After you provision Advanced Scheduler, the
ADVANCED_SCHEDULER_URL config var is available in your app’s configuration. It contains the canonical URL used to access the newly provisioned Advanced Scheduler service instance. You can confirm this via the
heroku config:get command:
$ heroku config:get ADVANCED_SCHEDULER_URL http://user:email@example.com/resourceid
After you install Advanced Scheduler, your application should be configured to fully integrate with the add-on. If you are new to task scheduling, you can read up on defining, testing and scheduling tasks below.
Tasks are any command that can be run in your application.
Almost every framework or language has a convention to define such a command. Some have a built-in feature for setting up tasks, while others require you to add a script to
bin/ that will perform the task.
Note that each framework or language might define tasks in a different way. Refer to the best practices for the framework or language you are using inside your application.
For Rails, the convention is to set up rake tasks. To create your scheduled tasks in Rails, copy the code below into
lib/tasks/scheduler.rake and customize it to fit your needs.
desc "This task is called by the Heroku scheduler add-on" task :update_feed => :environment do puts "Updating feed..." NewsFeed.update puts "done." end task :send_reminders => :environment do User.send_reminders end
#!/usr/bin/env ruby require "sequel" DB = Sequel.connect ENV["DATABASE_URL"] puts "Cleaning old sessions..." DB["DELETE FROM sessions WHERE last_seen_at < ?", Time.now - 24*60*60] puts "done."
Note that if you are using a script, an interpreter might be needed in the command above to execute your task correctly. To prevent this, add a shebang at the top of your script (e.g.,
#!/usr/bin/env node for Node.js or
#!/usr/bin/env ruby for Ruby). This tells the system which interpreter to use to execute the script.
Once you have written your task and see that it is functioning locally, the next step is to deploy your application and test your task on Heroku.
To do so, use
heroku run to run your task on Heroku:
$ heroku run <your-task>
To schedule a task, you need to create a new active trigger for it. Triggers are configured using the Advanced Scheduler dashboard.
Enter the task and specify if the trigger needs to be executed only once or at a certain time interval. For one-off triggers, define a date and time at which the task should be executed. For recurring triggers, provide a standard cron expression. As a tip, check your expressions here to verify they are correct. By default, a new trigger will be activated directly after creation. If you do not want this behaviour, you can configure the trigger to stay inactive.
Note that the time for tasks is in UTC. If you want to schedule the task at a certain local time, add the proper UTC offset.
Instead of specifying a command, you can specify one of the process types in your app’s Procfile. The command associated with the process type will then be executed, together with any parameters you supply. See the syntax for one-off dynos to learn more.
Note that for each plan there are limits on the total number of tasks that can be scheduled at one point in time, as well as the total number of task executions in one month. Once one of these limits is exceeded, attempts to schedule a new task will fail.
Scheduled tasks are meant be short running tasks. Longer running tasks must be enqueued into a background job queue. Anything that takes longer than a couple of minutes to complete should use a worker dyno to run.
Beware that a task must not run longer than its scheduling interval.
Concurrent one-off dyno limits
The limit for your app’s concurrently running one-off dynos depends on several factors. See which limit applies to your situation to learn more.
Beware that when exceeding your app’s concurrent one-off dyno limit, the next task might not be executed.
The Advanced Scheduler dashboard allows you to configure one-off and recurring triggers that execute different tasks.
You can access the dashboard via the CLI:
$ heroku addons:open advanced-scheduler Opening advanced-scheduler for sharp-mountain-4005
or by visiting the Heroku Dashboard and selecting the application in question. Select Advanced Scheduler from the Add-ons menu.
By default, Advanced Scheduler monitors the executions of your scheduled tasks. If applicable, for each task the numbed of failed executions in the last 24 hours is indicated in the Advanced Scheduler dashboard . In addition, for every task an alert e-mail is sent on the first failed execution each day.
Note that the successful or failed execution of your task depends on the process exit code, so make sure your process is exiting properly. When the process exits with code 0, the execution is considered successful. Anything else is treated as a failed execution.
The Advanced Scheduler add-on can be attached to additional apps by running the command:
$ heroku addons:attach advanced-scheduler -a APP_NAME
Migrating between plans
Note that application owners should carefully manage the migration timing to ensure proper application function during the migration process.
heroku addons:upgrade command to migrate to a new plan.
$ heroku addons:upgrade advanced-scheduler:newplan -----> Upgrading advanced-scheduler:newplan to sharp-mountain-4005... done, v18 ($49/mo) Your plan has been updated to: advanced-scheduler:newplan
Removing the add-on
You can remove Advanced Scheduler via the CLI:
This will destroy all associated data and cannot be undone!
$ heroku addons:destroy advanced-scheduler -----> Removing advanced-scheduler from sharp-mountain-4005... done, v20 (free)
All Advanced Scheduler support and runtime issues should be submitted via one of the Heroku Support channels. Any non-support related issues or product feedback is welcome at firstname.lastname@example.org.