12 Commits
Author SHA1 Message Date
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
Yim Lee 97df12eda3 Fix soundness script (#126) 2022-08-08 10:37:22 -07:00
Yim Lee 3dbb8b3a37 DocC setup (#125)
* DocC setup

* Fix formatting

* Fix CI for newer Swift versions

* Rename docc directory

* Revert non-docc related changes

* Revert non-docc related changes

* Use version-specific manifest for older Swift versions
2022-08-05 13:50:19 -07:00
tomer doron da0cb159aa update doc generation script (#117)
motivation: source-kitten has changed how its invoked

changes:
* invoke source-kitten with the correct flags
* make location of source-kitten source checkout more robust
* udpate module list
2021-12-16 15:17:14 -08:00
tomer doron faa9f17905 expose the underlying lifecycle for composition reasons (#70)
motivation: application frameworks thae use ServiceLifecycle may need to expose their underlying  lifecycle so they can be also composed into larger systems

changes:
* expose ServiceLifecycle::underlying
* make sure backtrace installer is only called once per process
* add swift-atomics dependency (>=5.2 and above)
* add atomic helper (<5.2)
2021-03-13 11:20:42 -08:00
tomer doron 19e0ab6b43 use welcoming language (#79) 2021-02-09 11:03:05 -08:00
tomer doron daef88b82a prepare to open source (#47)
motivation: cleanup naming and collatoral in preperation to open sourcing the library

changes:
* rename "bootstrap" to "lifecycle"
* contributors list
2020-07-15 14:57:44 -07:00
tomer doron d18349b069 update package name to swift-service-lifecycle (#39)
* update package name to swift-service-lifecycle

motivation: better name

changes: update package name and readme
2020-05-27 19:04:32 -07:00
tomer doron 0e2d952871 update readme to reflect updated API (#37)
motivation: keep readme in sync with code

changes:
* update readme to latest API + add nesting section
* update leftover renaming issues
2020-04-09 22:30:14 -07:00
tomer doron 77c2610f87 rename project to SwiftServiceBootstrap (#36)
motivation: better name

changes:
* update license headers
* update sanity checks
2020-04-09 21:23:49 -07:00
tomer doron b12bb032b5 add doc generation script (#13)
motivation: api docs

changes: add doc generation script
2020-03-31 20:22:30 -07:00
Tom Doron 1abe527c92 initial commit 2020-03-18 11:56:30 -07:00