fix: Add format, verbose options to scheduler
This commit is contained in:
parent
6b84c9ccf5
commit
4738a1422d
2 changed files with 20 additions and 7 deletions
|
|
@ -75,8 +75,12 @@ def disable_scheduler(context):
|
|||
@click.command("scheduler")
|
||||
@click.option("--site", help="site name")
|
||||
@click.argument("state", type=click.Choice(["pause", "resume", "disable", "enable", "status"]))
|
||||
@click.option(
|
||||
"--format", "-f", default="text", type=click.Choice(["json", "text"]), help="Output format"
|
||||
)
|
||||
@click.option("--verbose", "-v", is_flag=True, help="Verbose output")
|
||||
@pass_context
|
||||
def scheduler(context, state: str, site: str | None = None):
|
||||
def scheduler(context, state: str, format: str, verbose: bool = False, site: str | None = None):
|
||||
"""Control scheduler state."""
|
||||
import frappe
|
||||
import frappe.utils.scheduler
|
||||
|
|
@ -84,11 +88,18 @@ def scheduler(context, state: str, site: str | None = None):
|
|||
|
||||
site = site or get_site(context)
|
||||
|
||||
output = {
|
||||
"text": "Scheduler is {status} for site {site}",
|
||||
"json": '{{"status": "{status}", "site": "{site}"}}',
|
||||
}
|
||||
|
||||
with frappe.init_site(site=site):
|
||||
match state:
|
||||
case "status":
|
||||
frappe.connect()
|
||||
status = "disabled" if frappe.utils.scheduler.is_scheduler_inactive(verbose=verbose) else "enabled"
|
||||
status = (
|
||||
"disabled" if frappe.utils.scheduler.is_scheduler_inactive(verbose=verbose) else "enabled"
|
||||
)
|
||||
return print(output[format].format(status=status, site=site))
|
||||
case "pause" | "resume":
|
||||
update_site_config("pause_scheduler", state == "pause")
|
||||
|
|
@ -97,7 +108,7 @@ def scheduler(context, state: str, site: str | None = None):
|
|||
frappe.utils.scheduler.toggle_scheduler(state == "enable")
|
||||
frappe.db.commit()
|
||||
|
||||
print(f"Scheduler {state}d for site {site}")
|
||||
print(output[format].format(status=f"{state}d", site=site))
|
||||
|
||||
|
||||
@click.command("set-maintenance-mode")
|
||||
|
|
|
|||
|
|
@ -92,16 +92,18 @@ def enqueue_events(site: str) -> list[str] | None:
|
|||
return enqueued_jobs
|
||||
|
||||
|
||||
def is_scheduler_inactive() -> bool:
|
||||
def is_scheduler_inactive(verbose=True) -> bool:
|
||||
if frappe.local.conf.maintenance_mode:
|
||||
cprint(f"{frappe.local.site}: Maintenance mode is ON")
|
||||
if verbose:
|
||||
cprint(f"{frappe.local.site}: Maintenance mode is ON")
|
||||
return True
|
||||
|
||||
if frappe.local.conf.pause_scheduler:
|
||||
cprint(f"{frappe.local.site}: frappe.conf.pause_scheduler is SET")
|
||||
if verbose:
|
||||
cprint(f"{frappe.local.site}: frappe.conf.pause_scheduler is SET")
|
||||
return True
|
||||
|
||||
if is_scheduler_disabled():
|
||||
if is_scheduler_disabled(verbose=verbose):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue