11 Commits
Author SHA1 Message Date
Franz Busch 0fcc4c9c2d Include the service name in the serviceFinishedUnexpectedly error (#217)
## Motivation

To aid debugging and troubleshooting, it is helpful to understand which
Service led to the error.

## Modifications

Add the service name to the `serviceFinishedUnexpectedly` error.

## Result

Easier to debug failing services.
2025-10-08 09:40:06 +02:00
Joseph Heck 83cecce066 extending the documentation content (#212)
- cleaning up grammar to use present tense and more direct phrasing
- extending documentation coverage

Current state:
```
                | Abstract        | Curated         | Code Listing
Types           | 71% (10/14)     | 64% (9/14)      | 0.0% (0/14)
Members         | 44% (49/111)    | 77% (85/111)    | 0.0% (0/111)
Globals         | 73% (8/11)      | 91% (10/11)     | 9.1% (1/11)
```
2025-09-19 08:31:20 +00:00
Joseph Heck 4c5efa9806 adding abstracts and organization to methods (#205)
A little bit of docs cleanup - adding abstracts for deprecated methods
and curating them (organizing them) to the bottom of the relevant lists.
2025-05-06 19:19:53 +00:00
Michael Gecht 24ea9176ab Update documentation (#195) 2025-01-08 13:12:13 +00:00
Evren SenandFranz Busch 0af4033d87 Make logging optional and update docs (#189)
Hello! 👋 This PR contains a few changes, notably:

- Updating the ``README.md`` to use the new initializer instead of the
deprecated one.
- Add a ``renamed`` to the deprecated initializer.
- Updating the docs to use the simpler initializer.
- Make the ``logging`` parameter on the initializers optional, the
motivation for this is in cases the user don't or can't do logging, they
don't have to construct a logger and bootstrap the logging system with
``SwiftLogNoOpLogHandler``, so this code:
```swift
LoggingSystem.bootstrap(SwiftLogNoOpLogHandler.init)
let serviceGroup = ServiceGroup(
    services: [service],
    cancellationSignals: [.sigint],
    logger: .init(label: "")
)
```
becomes
```swift
let serviceGroup = ServiceGroup(
    services: [service],
    cancellationSignals: [.sigint]
)
```
and it also allows the user to do logging outside the ServiceGroup
without necessarily doing logging within it.

If there is anything to improve, let me know! 😃

*thanks dimi and gwynne for helping along the way and answering my
questions :)*

---------

Co-authored-by: Franz Busch <privat@franz-busch.de>
2024-12-05 15:14:08 +00:00
Tibor BödecsandFranz Busch b21c43a7c1 Update readme instructions & version (#164)
* update readme instructions & version

* add full package example

* Update README.md

Co-authored-by: Franz Busch <privat@franz-busch.de>

* Update README.md

Co-authored-by: Franz Busch <privat@franz-busch.de>

* add getting started to docc index

---------

Co-authored-by: Franz Busch <privat@franz-busch.de>
2024-01-25 06:29:19 -08:00
Max Desiatov 05031271bf Update TerminationBehavior doc comments and notes (#165)
* Mention `TerminationBehavior` in library adoption docs

`ServiceGroupConfiguration.ServiceConfiguration.TerminationBehavior` did not seem to be mentioned in the docs and specifically library adoption docs gave the impression that cancellation on returning from `run` is the only option.

* Update relevant documentation
2024-01-25 14:24:30 +00:00
Honza Dvorsky e4592be5e6 Docs fix - put group.addTask inside the loop (#156)
* Docs fix - put group.addTask inside the loop

* Update How to adopt ServiceLifecycle in applications.md
2023-08-24 10:09:15 +01:00
Honza Dvorsky 2becb2433a Fix a typo in docs (#155) 2023-08-24 10:09:06 +01:00
Franz Busch f58dbbfaa9 Add support for return/ThrowBehavior of services (#148)
* Add support for `return/ThrowBehavior` of services

# Motivation

Currently the `ServiceGroup` cancels the whole group when a service returns or throws. This is fine for most server applications but it doesn't work for CLI tools since they mostly want to use the group to orchestrate the services as long as the user command is handled and then return cleanly from the group. Furthermore, even on server setups one might want to customize the behavior of what happens when a service returns/throws e.g. one might want to shutdown the group after their HTTP server throws so that a telemetry service flushes out all the remaining data.

# Modification

This PR does a few things:
1. It creates a new `ServiceConfiguration` and `TerminationBehavior` in the `ServiceGroupConfiguration`. Those can be used to declare the services that are run and what happens when the service returns or throws
2. Adds a new `cancellationSignals` to to the `ServiceGroupConfiguration` which allows cancellation to trigger based on a signal
3. Makes sure that any given service is only retained as long as necessary i.e. when a service returns the group is not retaining it anymore. This allows freeing of resources as early as possible
4. Breaking: Removes the `Hashable` conformance on the configuration structs. This was wrong in the first place and something we should just avoid doing in general.

# Result
We now give the user even more control about the group's behaviors.

* Review

* Review

* Fix CI
2023-08-16 13:22:22 +01:00
Franz Busch fafab8f7ad Overhaul service lifecycle for Structured Concurrency (#130)
* Overhaul service lifecycle for Structured Concurrency

# Motivation
Since the release of Swift Concurrency the server ecosystem has adopted `async`/`await` in a lot of APIs making the user experience amazing. Another thing that Swift Concurrency introduced is Structured Concurrency which allows to create a task tree that with parent to child relations. Structured Concurrency has many benefits such as automatic cancellation and task local propagation.
The current state of this library predates the introduction of Swift Concurrency and is not inline anymore with how applications are structured that want to leverage Concurrency.

# Modification
This PR overhauls the implementation of service lifecycle completely. The reason for this is that the current implementation is very focused on how NIO based applications work before the introduction of Concurrency. Furthermore, Structured Concurrency is actually replacing part of the current functionality by providing new scoping mechanisms.
The overhauled implementation provides two primitive types. Anew `Service` protocol and a `ServiceRunner`. The former is providing a clear API which services have to conform to so that they can be run by the `ServiceRunner`.

An example usage of the types looks like this

```swift
actor FooService: Service {
    func run() async throws {}

    func shutdownGracefully() async throws {}
}
actor BarService: Service {
    func run() async throws {}

    func shutdownGracefully() async throws {}
}

let fooService = FooService()
let barService = BarService()

let runner = ServiceRunner(
    services: [fooService, barService],
   configuration: .init(),
   logger: logger
)

try await runner.run()
```

# Result
We now have a service lifecycle library that integrates nicely with Structured Concurrency. Its value add is that it solves to complex setup of the task group with the signal handling. Furthermore, it provides a currency type `Service` that can be passed to inject services.

* Remove `shutdownGracefully` method and switch to a handler based approach.

* Code review from George

* Add extensions to `TaskGroup` and `ThrowingTaskGroup`

* Remove long running property

* Documentation

* Fix tests

* Ensure ordering of shutdown

* Test

# Motivation

# Modification

# Result

* Introduce ServiceLifecycleTestKit

* Add AsyncCancelOngracefulShutdownSequence

* Tests and docs for graceful shutdown

# Motivation

# Modification

# Result

* Remove unsafe flags

* Add article for application authors

* Add correct licence and notice information for the things we copied from swift-nio

* Code review

* Remove @_unsafeInheritExectuor

* Code review

* Change log levels, rename to withGracefulShutdownHandler and support nested service runner graceful shutdown

* Add public `shutdownGracefully` method to the service runner

* Code review and expose new cancelOnGracefulShutdown method

* Extend graceful shutdown APIs and tolerate running outside of a `ServiceRunner`

* Rename to `ServiceGroup`

* Enable Swift 5.6 support

* Update soundess dockerfile

* Update Readme

* Make 5.6 build work
2023-04-27 11:56:08 +01:00