Does Maintenance Mode Disable Scheduler on Heroku
Categories:
Does Heroku Maintenance Mode Disable the Scheduler?

Explore the interaction between Heroku's Maintenance Mode and the Heroku Scheduler, understanding how scheduled tasks behave during application downtime.
Heroku's Maintenance Mode is a crucial feature for performing updates or debugging without exposing users to a broken application. However, a common question arises regarding its impact on background processes, specifically the Heroku Scheduler. This article clarifies whether Maintenance Mode disables scheduled tasks and provides best practices for managing your application during downtime.
Understanding Heroku Maintenance Mode
Heroku's Maintenance Mode is designed to gracefully take your application offline. When enabled, all web dynos stop serving traffic, and any incoming requests are redirected to a static maintenance page. This allows you to perform database migrations, deploy significant code changes, or troubleshoot issues without affecting user experience. While web traffic is halted, other dyno types, such as worker dynos, typically continue to run unless explicitly stopped or scaled down.
Heroku Scheduler and Maintenance Mode Interaction
The Heroku Scheduler is a separate add-on that runs tasks at specified intervals. These tasks are executed as one-off dynos. A key distinction is that Heroku Scheduler tasks are not directly tied to your web dynos. They are independent processes initiated by the Scheduler add-on itself.
The short answer is: No, Heroku Maintenance Mode does not disable the Heroku Scheduler.
When Maintenance Mode is active, your web dynos are offline, but the Heroku Scheduler continues to operate. If a scheduled task's time arrives while Maintenance Mode is on, the Scheduler will attempt to provision and run a one-off dyno for that task. This dyno will execute its assigned command, potentially interacting with your database or other services, even if your main application is inaccessible via the web.
flowchart TD A[User Request] --> B{Heroku Router} B -->|Maintenance Mode ON| C[Maintenance Page] B -->|Maintenance Mode OFF| D[Web Dyno] E[Heroku Scheduler] --> F{Scheduled Task Time} F --> G[Provision One-Off Dyno] G --> H[Execute Task Command] H --> I[Database/External Service] C --x D E -- Always Active --> F
Interaction between Heroku Router, Maintenance Mode, and Heroku Scheduler
Implications and Best Practices
Since scheduled tasks continue to run during Maintenance Mode, it's crucial to consider the implications for your application's integrity and data consistency. Here are some best practices:
- Review Task Dependencies: If your scheduled tasks rely on the web application being fully operational (e.g., making API calls to itself, or assuming certain application states), they might fail or cause unexpected behavior during maintenance.
- Conditional Execution: Implement logic within your scheduled tasks to check for Maintenance Mode. You can use environment variables or a simple flag in your database to determine if the application is under maintenance and skip execution if necessary.
- Manual Disabling: For critical tasks that absolutely must not run during maintenance, you might need to manually disable them in the Heroku Scheduler dashboard before enabling Maintenance Mode and re-enable them afterward.
- Use a Dedicated Worker Dyno: For long-running or critical background jobs, consider using a dedicated worker dyno instead of the Heroku Scheduler. Worker dynos can be scaled down to zero during maintenance, giving you more direct control.
- Test Your Maintenance Procedures: Always test your maintenance procedures, including how scheduled tasks behave, in a staging environment before applying them to production.
# Example: Conditional execution in a Ruby Rake task
namespace :app do
desc "Perform a daily cleanup task"
task :daily_cleanup => :environment do
if ENV['HEROKU_MAINTENANCE_MODE'] == 'true'
puts "Skipping daily cleanup due to Maintenance Mode."
else
puts "Performing daily cleanup..."
# Your cleanup logic here
end
end
end
Example of conditional task execution based on an environment variable
HEROKU_MAINTENANCE_MODE=true
) when entering maintenance and check for it in your scheduled tasks to prevent unwanted execution.