How to Enable or Disable the Background Job Scheduler in Frappe/ERPNext
Enable/Disable SchedulerA guide to using the 'bench enable-scheduler' and 'bench disable-scheduler' CLI commands to control background job processing for your Frappe or ERPNext sites.
The Frappe Framework relies on a scheduler to run background jobs, such as sending scheduled emails, running automated reports, and processing workflows. At times, you may need to stop the scheduler for maintenance, debugging, or to prevent jobs from running on a development or staging site. The `bench` command-line interface provides a simple way to toggle the scheduler on and off for any specific site.
//Enable-Disable Scheduler
bench --site site1.local enable-scheduler
bench --site site1.local disable-schedulerUnderstanding This Code
What It Does
These commands either enable or disable the Frappe scheduler for a specified site. Enabling the scheduler allows background workers to pick up and execute scheduled jobs, while disabling it prevents any new jobs from being run.
When To Use
Use these commands during system maintenance, before restoring a database backup, or on development/staging sites where you want to prevent automated tasks (like sending emails to real customers) from executing.
Prerequisites
- •Access to the server terminal where your Frappe bench is installed.
- •Sudo or bench user permissions to execute bench commands.
Key Concepts
Important ideas to understand in this code
Bench CLI
The 'bench' command-line interface is the primary tool for managing Frappe Framework installations, including sites, apps, and system processes like the scheduler and workers.
Learn moreFrappe Scheduler
The scheduler is a crucial component responsible for queuing and executing background jobs at specified intervals. It handles recurring tasks defined in hooks.py or through the 'Scheduled Job Type' DocType.
Learn moreSite-Specific Configuration
The '--site' flag allows you to target a specific site within your bench. This is essential in a multi-tenant environment, ensuring you only affect the intended site's scheduler.
Learn moreStep-by-Step Tutorial
Follow along to understand how this code works
Connect to Your Server Terminal
First, you need to establish an SSH connection to the server where your Frappe bench is located. You'll need the server's IP address and your login credentials.
ssh your_user@your_server_ipNavigate to the Bench Directory
Change your current directory to the root of your bench installation. This is typically named 'frappe-bench'.
cd ~/frappe-benchDisable the Scheduler
To stop the scheduler for a specific site, use the 'disable-scheduler' command. Replace 'site1.local' with the name of your target site.
bench --site site1.local disable-schedulerEnable the Scheduler
Once your maintenance is complete, you can re-enable the scheduler using the 'enable-scheduler' command. This will allow background jobs to resume processing.
bench --site site1.local enable-schedulerCommon Issues & Solutions
Troubleshoot problems you might encounter