Frappe CLIbash

How to Enable or Disable the Background Job Scheduler in Frappe/ERPNext

Enable/Disable Scheduler

A 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.

Terminalbash
//Enable-Disable Scheduler
bench --site site1.local enable-scheduler
bench --site site1.local disable-scheduler

Understanding 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 more

Frappe 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 more

Site-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 more

Step-by-Step Tutorial

Follow along to understand how this code works

1

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.

bash
ssh your_user@your_server_ip
Next Step
2

Navigate to the Bench Directory

Change your current directory to the root of your bench installation. This is typically named 'frappe-bench'.

bash
cd ~/frappe-bench
Next Step
3

Disable 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.

bash
bench --site site1.local disable-scheduler
Next Step
4

Enable 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.

bash
bench --site site1.local enable-scheduler

Common Issues & Solutions

Troubleshoot problems you might encounter