Skip to content

Commit

Permalink
add the functionality for stopping the task
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijeetSaroha committed Dec 23, 2024
1 parent ee0801a commit 05d81d4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/makim/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def run_app() -> None:
)

@typer_cron.command(help="List all scheduled tasks")
def list():
def list() -> None:
"""List all scheduled tasks."""
if not makim.scheduler:
typer.echo("No scheduled tasks configured.")
Expand All @@ -160,7 +160,7 @@ def list():
console.print(table)

@typer_cron.command(help="Start a scheduler by its name")
def start(name: str):
def start(name: str) -> None:
"""Start (enable) a scheduled task."""
if not makim.scheduler:
typer.echo("No scheduler configured.")
Expand All @@ -183,10 +183,19 @@ def start(name: str):
typer.echo(f"Failed to start schedule '{name}': {e}", err=True)

@typer_cron.command(help="Stop a scheduler by its name")
def stop(name: str):
print("Stop")
def stop(name: str) -> None:
"""Stop (disable) a scheduled task."""
if not makim.scheduler:
typer.echo("No scheduler configured.")
return

try:
makim.scheduler.remove_job(name)
typer.echo(f"Successfully stopped schedule '{name}'")
except Exception as e:
typer.echo(f"Failed to stop schedule '{name}': {e}", err=True)

app.add_typer(typer_cron, name="cron", rich_help_panel="Extensions")
app.add_typer(typer_cron, name="cron", rich_help_panel="Extensions")

# Add dynamically created commands to the Typer app
for name, args in tasks.items():
Expand Down

0 comments on commit 05d81d4

Please sign in to comment.