-
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.
- Loading branch information
Showing
11 changed files
with
368 additions
and
232 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
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,13 @@ | ||
# Task Scheduler | ||
|
||
The task scheduler [TaskScheduler][fluid.scheduler.TaskScheduler] inherits | ||
from the [TaskConsumer][fluid.scheduler.TaskConsumer] to add scheduling of | ||
periodic tasks. | ||
|
||
It can be imported from `fluid.scheduler`: | ||
|
||
```python | ||
from fastapi.scheduler import TaskScheduler | ||
``` | ||
|
||
::: fluid.scheduler.TaskScheduler |
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,52 @@ | ||
# Task Queue App | ||
|
||
The `fluid.scheduler` module is a simple yet powerful distributed task producer ([TaskScheduler][fluid.scheduler.TaskScheduler]) and consumer ([TaskConsumer][fluid.scheduler.TaskConsumer]) system for executing tasks. | ||
The middleware for distributing tasks can be configured via the [TaskBroker][fluid.scheduler.TaskBroker] interface. | ||
|
||
A redis task broker is provided for convenience. | ||
|
||
## Tasks Consumer | ||
|
||
Create a task consumer, register tasks from modules, and run the consumer. | ||
|
||
```python | ||
import asyncio | ||
from typing import Any | ||
from fluid.scheduler import TaskConsumer | ||
import task_module_a, task_module_b | ||
|
||
|
||
def task_consumer(**kwargs: Any) -> TaskConsumer: | ||
consumer = TaskConsumer(**kwargs) | ||
consumer.register_from_module(task_module_a) | ||
consumer.register_from_module(task_module_b) | ||
return consumer | ||
|
||
|
||
if __name__ == "__main__": | ||
consumer = task_consumer() | ||
asyncio.run(consumer.run()) | ||
``` | ||
|
||
## FastAPI Integration | ||
|
||
The `TaskConsumer` can be integrated with FastAPI so that | ||
tasks can be queued via HTTP requests. | ||
|
||
```python | ||
import uvicorn | ||
from fluid.scheduler.endpoints import setup_fastapi | ||
|
||
if __name__ == "__main__": | ||
consumer = task_consumer() | ||
app = setup_fastapi(consumer) | ||
uvicorn.run(app) | ||
``` | ||
|
||
You can test via the example provided | ||
|
||
```bash | ||
python -m examples.simple_fastapi | ||
``` | ||
|
||
and check the openapi UI at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs). |
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,8 @@ | ||
import asyncio | ||
|
||
from examples.tasks import task_scheduler | ||
from fluid.utils import log | ||
|
||
if __name__ == "__main__": | ||
log.config() | ||
asyncio.run(task_scheduler().run()) |
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,10 @@ | ||
import uvicorn | ||
|
||
from examples.tasks import task_scheduler | ||
from fluid.scheduler.endpoints import setup_fastapi | ||
from fluid.utils import log | ||
|
||
if __name__ == "__main__": | ||
log.config() | ||
app = setup_fastapi(task_scheduler()) | ||
uvicorn.run(app) |
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
Oops, something went wrong.