Skip to content

Commit

Permalink
feat: Add method create_task to the TaskManager class
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab authored Jun 7, 2024
1 parent bb90d63 commit 07379b8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/retsu/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ def __init__(self) -> None:
"""Create a list of retsu tasks."""
self.tasks: dict[str, Task] = {}

@public
def create_tasks(self) -> None:
"""Get a task with the given name."""
if self.tasks:
return

warnings.warn(
"`self.tasks` is empty. Override `create_tasks` and create "
"`self.tasks` with the proper tasks."
)

@public
def get_task(self, name: str) -> Optional[Task]:
"""Get a task with the given name."""
Expand All @@ -144,13 +155,20 @@ def get_task(self, name: str) -> Optional[Task]:
@public
def start(self) -> None:
"""Start tasks."""
if not self.tasks:
self.create_tasks()

for task_name, task in self.tasks.items():
print(f"Task `{task_name}` is starting ...")
task.start()

@public
def stop(self) -> None:
"""Stop tasks."""
if not self.tasks:
warnings.warn("There is no tasks to be stopped.")
return

for task_name, task in self.tasks.items():
print(f"Task `{task_name}` is stopping ...")
task.stop()

0 comments on commit 07379b8

Please sign in to comment.