Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions matrix/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def __init__(self) -> None:
def jobs(self) -> list[Job]:
return cast(list[Job], self.scheduler.get_jobs())

def list_jobs(self) -> list[str]:
"""Return a list of names of all registered jobs."""
return [job.name for job in self.jobs]

def _parse_cron(self, cron: str) -> dict:
"""
Parse a cron string into a dictionary suitable for CronTrigger.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from matrixpy.scheduler import Scheduler


def test_list_jobs_expect_empty() -> None:
"""Verify list_jobs returns an empty list on initialization."""
scheduler = Scheduler()
assert scheduler.list_jobs() == []


def test_list_jobs_with_active_jobs() -> None:
"""Verify list_jobs returns the names of the scheduled jobs."""
scheduler = Scheduler()

class MockJob:

def __init__(self, name: str) -> None:
self.name: str = name

scheduler.jobs = [MockJob("job_1"), MockJob("job_2")]

assert scheduler.list_jobs() == ["job_1", "job_2"]