Skip to content

Commit

Permalink
update the cli init file
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijeetSaroha committed Dec 23, 2024
1 parent b249793 commit ee0801a
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/makim/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
)
from makim.cli.config import CLI_ROOT_FLAGS_VALUES_COUNT, extract_root_config
from makim.core import Makim
from rich.table import Table
from rich.console import Console

app = typer.Typer(
help=(
Expand Down Expand Up @@ -138,11 +140,47 @@ def run_app() -> None:

@typer_cron.command(help="List all scheduled tasks")
def list():
print("list")
"""List all scheduled tasks."""
if not makim.scheduler:
typer.echo("No scheduled tasks configured.")
return

console = Console()
table = Table(show_header=True, header_style="bold")
table.add_column("Name")
table.add_column("Next Run")

jobs = makim.scheduler.list_jobs()
for job in jobs:
table.add_row(
job['name'],
job['next_run_time'] or "Not scheduled"
)

console.print(table)

@typer_cron.command(help="Start a scheduler by its name")
def start(name: str):
print("start")
"""Start (enable) a scheduled task."""
if not makim.scheduler:
typer.echo("No scheduler configured.")
return

try:
schedule_config = makim.global_data.get("scheduler", {}).get(name)
if not schedule_config:
typer.echo(f"No configuration found for schedule '{name}'")
return

makim.scheduler.add_job(
name=name,
schedule=schedule_config["schedule"],
task=schedule_config["task"],
args=schedule_config.get("args", {})
)
typer.echo(f"Successfully started schedule '{name}'")
except Exception as e:
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):
Expand Down

0 comments on commit ee0801a

Please sign in to comment.