asynchronous application orchestrator
Project description
It is a small library, which solves single task: orchestration of asynchronous applications.
For example, we have an application, which consists of database, message queue, web API, and background workers. Database and message queue are independent, they can be launched concurrently. Web API and background workers are independent too. But they both depend on database and message queue. So they should be launched after and stopped before database and message queue.
This is how it can be solved using AIOConductor.
from aioconductor import Conductor, Component
class Database(Component):
async def setup(self):
""" Setup database """
async def shutdown(self):
""" Shutdown database """
class MessageQueue(Component):
async def setup(self):
""" Setup message queue """
async def shutdown(self):
""" Shutdown message queue """
class WebAPI(Component):
db: Database # Dependencies are declared by type annotations.
queue: MessageQueue # Real instances of the components will be injected
# during setup routine.
async def setup(self):
""" Setup web API """
async def shutdown(self):
""" Shutdown web API """
class BackgroundWorkers(Component):
db: Database
queue: MessageQueue
async def setup(self):
""" Setup background workers """
async def shutdown(self):
""" Shutdown background workers """
conductor = Conductor(config={})
conductor.add(WebAPI)
conductor.add(BackgroundWorkers)
conductor.serve()
The code above will run concurrent setup of Database and MessageQueue, and then concurrent setup of WebAPI and BackgroundWorkers. Shutdown will be run in opposite order.
Conductor also provides ability to patch component by alternative implementation. It can be useful for testing.
class MessageQueueMock(Component):
async def setup(self):
""" Setup message queue mock """
async def shutdown(self):
""" Shutdown message queue mock """
conductor = Conductor(config={})
conductor.patch(MessageQueue, MessageQueueMock)
# An instance of ``MessageQueueMock`` will be injected into
# ``WebAPI`` and ``BackgroundWorkers``, instead of ``MessageQueue``.
conductor.add(WebAPI)
conductor.add(BackgroundWorkers)
conductor.serve()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file AIOConductor-0.1-py36-none-any.whl
.
File metadata
- Download URL: AIOConductor-0.1-py36-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3.6
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 103bc83fa79d6b84e237dbb40044ed3e99412d1b553eba118314a6b56af795c4 |
|
MD5 | 319c22d0f0aaba5e66b5c047aec1065f |
|
BLAKE2b-256 | 8cce2753e3e2b08984852b502224c78a05f6a60b2a9b2c50da6c1b5911af02cc |