Skip to content
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

Merged
merged 10 commits into from
Jul 30, 2024

Commits on Jul 26, 2024

  1. Remove Returns: from properties docstrings

    This is not necessary, as properties should be documented as attributes.
    
    Signed-off-by: Leandro Lucarella <[email protected]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    d200e54 View commit details
    Browse the repository at this point in the history
  2. Rename BackgroundService to Service

    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]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    71b5fc5 View commit details
    Browse the repository at this point in the history
  3. Use a more human-friendly format for the admonitions

    Signed-off-by: Leandro Lucarella <[email protected]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    a7a7131 View commit details
    Browse the repository at this point in the history
  4. Add a new TaskCreator protocol

    This 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]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    eb0848f View commit details
    Browse the repository at this point in the history
  5. 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]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    e39f292 View commit details
    Browse the repository at this point in the history
  6. 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]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    bc98971 View commit details
    Browse the repository at this point in the history
  7. 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]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    b6ed4bd View commit details
    Browse the repository at this point in the history
  8. 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]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    47bef4a View commit details
    Browse the repository at this point in the history
  9. Make Service an ABC and add a ServiceBase

    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]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    0f4ca6b View commit details
    Browse the repository at this point in the history
  10. Make wait() private

    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]>
    llucax committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    520beaa View commit details
    Browse the repository at this point in the history