-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from AKVorrat/scheduler-logic-state
General scheduling logic
- Loading branch information
Showing
8 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Scheduler | ||
|
||
The scheduler handles background tasks of the application. It is logically | ||
seperated by "modules" with each module holding tasks. | ||
|
||
## Module | ||
|
||
Currently implemented `modules` are: | ||
|
||
* `calls` | ||
|
||
## Task Arguments | ||
|
||
Example: | ||
```yml | ||
interval: 20.2 # in seconds, Optional as Tasks have their own default values | ||
wait_first: false # true(default) or false, Optional | ||
``` | ||
### interval | ||
Time in seconds after which the task is executed again. | ||
### wait_first | ||
Optional. Defaults to `false`. If set to `true` the task's first execution is | ||
after `seconds`, not immediately after startup. | ||
|
||
## Calls Module | ||
|
||
The `calls` module allows for scheduled, call relevant functions to be executed | ||
regularly. | ||
|
||
Currently supports the tasks: | ||
|
||
* `build_queue` | ||
* `handle_queue` | ||
|
||
### build_queue | ||
|
||
This task builds a queue of Users who have given the information that they | ||
wanted to be called at the current time. | ||
|
||
### handle_queue | ||
|
||
This task checks the queue created by `build_queue` and makes a single phone | ||
call to the first user in the queue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Callable, List, Tuple | ||
|
||
from fastapi_utils.tasks import repeat_every | ||
|
||
from .calls import build_queue, handle_queue | ||
from ..config import Config, SchedulerTaskConfig | ||
|
||
SchedulerTask = Callable[[], None] | ||
|
||
|
||
def get_background_tasks(config: Config): | ||
""" | ||
Returns a list of configured background tasks to be run at startup. | ||
""" | ||
tasks: List[Tuple[SchedulerTaskConfig, SchedulerTask]] = [] | ||
|
||
if not config.scheduler: | ||
return [] | ||
|
||
if config.scheduler.calls: | ||
# We add our tasks to the list of tasks to be run at startup if we find | ||
# their config. | ||
if (build_queue_cfg := config.scheduler.calls.build_queue): | ||
tasks.append((build_queue_cfg, build_queue)) | ||
|
||
if (handle_queue_cfg := config.scheduler.calls.handle_queue): | ||
tasks.append((handle_queue_cfg, handle_queue)) | ||
|
||
return [ | ||
repeat_every( | ||
seconds=cfg.interval, | ||
wait_first=cfg.wait_first, | ||
)(func) for cfg, func in tasks] | ||
|
||
|
||
__all__ = [ | ||
"get_background_tasks", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def build_queue() -> None: | ||
pass | ||
|
||
|
||
def handle_queue() -> None: | ||
pass |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters