-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revamp BackgroundService
and rename to Service
#27
Commits on Jul 26, 2024
-
Remove
Returns:
from properties docstringsThis is not necessary, as properties should be documented as attributes. Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for d200e54 - Browse repository at this point
Copy the full SHA d200e54View commit details -
Rename
BackgroundService
toService
The name `BackgroundService` is a bit too verbose now in the context of an asyncio library. Services are usually already understood as running in the background, so the `Background` prefix is redundant and makes the class name too long. Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 71b5fc5 - Browse repository at this point
Copy the full SHA 71b5fc5View commit details -
Use a more human-friendly format for the admonitions
Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for a7a7131 - Browse repository at this point
Copy the full SHA a7a7131View commit details -
Add a new
TaskCreator
protocolThis will be used in the future to allow overriding where to create tasks (for example the default `asyncio` loop, a custom `loop` or even a `TaskGroup`). Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for eb0848f - Browse repository at this point
Copy the full SHA eb0848fView commit details -
Use the task creator object to create tasks in the Service class
This change adds a new parameter to the Service class, `task_creator`, that will be used to create tasks. This is useful to allow the user to use different task creators, like the `asyncio` module or a `TaskGroup`. A method to create tasks was also added to the Service class, that uses the task creator object to create the tasks, hopefully making it easier for users not to forget to register tasks managed by the service in the `self._tasks` set. Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for e39f292 - Browse repository at this point
Copy the full SHA e39f292View commit details -
Add an option to log exceptions raised by tasks
It is common that users forget to handle exceptions properly in their tasks, and since services tasks are supposed to run forever, there are no many opportunities to await for their completion appropriately and handle the failure. With this at least we make sure we will get a log message when a task raises an exception, so we can at least know what happened and they just silently disappear. Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for bc98971 - Browse repository at this point
Copy the full SHA bc98971View commit details -
Add the service representation to managed task names
This makes it much easier when debugging to know which service spawned each task. Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for b6ed4bd - Browse repository at this point
Copy the full SHA b6ed4bdView commit details -
Improve warning about holding a reference to
Service
The warning is not very clear and might suggest users need to hold references to the service's tasks, which is not correct, only a reference to the service itself should be saved. Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 47bef4a - Browse repository at this point
Copy the full SHA 47bef4aView commit details -
Make
Service
an ABC and add aServiceBase
By having both mixed up, it was hard to separate documentation for users of services, and developers wanting to implement services. It also gave access to service users to internals for service implementation, like `create_task`, which is not ideal. Now users can use the `Service` type to refer to services generically and implementors can use `ServiceBase` to have a sane starting point to implement a service. Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 0f4ca6b - Browse repository at this point
Copy the full SHA 0f4ca6bView commit details -
We don't really need to make it a public method, as one can just use `await service` to await for it. It is still good to have it separate as implementing `__await__` is easier based on another awaitable. Signed-off-by: Leandro Lucarella <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 520beaa - Browse repository at this point
Copy the full SHA 520beaaView commit details