24 Commits
Author SHA1 Message Date
Rick Newton-RogersandYim Lee 4d11d9817d Bump minimum Swift version to 5.7 (#160)
* Bump minimum Swift version to 5.7

Motivation:

Now that Swift 5.9 is GM we should update the supported versions and
remove 5.6

Modifications:

* Update `Package.swift`
* Delete the <5.7 docker compose files and make a 5.10 one
* Update the 5.9 docker file to stop using nightlies

Result:

Remove support for Swift 5.6, add 5.10

* Remove '--enable-test-discovery'

To see if it's causing CI build getting stuck

---------

Co-authored-by: Yim Lee <yim_lee@apple.com>
2023-10-05 10:44:21 +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
Yim Lee 7b60c92186 Add docker-compose for Swift 5.9 (#131)
Also update `main` nightly to Ubuntu 22.04
2023-04-04 20:53:19 -07:00
tomer doron b7628eb6b3 add docker compose setup for swift 5.8 (#129)
motivation: prepare for swift 5.8

changes:
* update use of Locks to address NIO warnings
* update docker compose setup to use release version of 5.7
* add docker compose setup for 5.8
2023-04-04 19:54:32 -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 22363fed31 add the ability to de-register a task (#121)
motivation: sometimes a task needs to be de-registered since the task was manually shutdown outside the lifecycle scope

changes:
* registration APIs now return a registration key which can be used as a cancellation token
* add API to de-register a task
* refactor state to use a registery instead of array of tasks
* add tests
2022-06-13 10:28:56 -07:00
tomer doron e63be9ef46 ci update (#119)
motivation: 5.6 is out

changes:
* use release version of 5.6
* add docker setup for 5.7 (using nightly for now)
2022-03-16 21:20:22 -07:00
tomer doron efb1d749af Use release version of 5.5 in CI (#112)
motivation: 5.5 release is available

changes: update docker CI setup to use the release version of 5.5
2021-09-22 17:13:43 -07:00
tomer doron f6c02f7b46 only install jazzy on latest ubuntu versions (#108)
motivation: jazzy no longer works on older version of ubuntu as ruby is too old

changes: update docker to only install jazzy on latest ubuntu versions
2021-09-01 22:45:00 -07:00
tomer doron b00bee04fd add 5.5 ci (#105)
motivation: test with 5.5

changes: add 5.5. docker-compose and pin jazzy version
2021-08-19 14:45:13 -07:00
tomer doron ad8631e430 update 5.4 to release docker image (#98)
motivation: 5.4 is out!

changes: use release docker images instead of nightly
2021-05-06 17:57:32 -07:00
tomer doron 727db6c591 Update docker-compose.2004.main.yaml (#97)
motivation: fix nightly docker setup

changes: fix typo
2021-05-06 17:42:24 -07: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 1e2fa84316 add 5.4 and nightly ci jobs (#82)
motivation: prepare for 5.4 and test against nightlies

changes:
* add docker compose setup for 5.4 and nightly testing
2021-03-11 10:34:53 +09:00
tomer doron 19e0ab6b43 use welcoming language (#79) 2021-02-09 11:03:05 -08:00
tomer doron a7932002e9 remove symbolicate-linux-fatal from Docker (#76)
motivation: we are not actually using symbolicate-linux-fatal in any meaningful way in CI and it's pinned to the master branch which has been removed

changes: remove symbolicate-linux-fatal fetching from Docker
2020-10-08 09:14:17 +09:00
tomer doron adb39391ff Swift 5.3 was released, use if for CI (#74)
motivation: Swift 5.3 was released, use if for CI

changes: update docker setup to use the release version of 5.3
2020-09-20 19:00:40 -07:00
tomer doron c8e99520d7 setup shutdown hooks on ServiceLifecycle::startAndWait (#69)
motivation: fix startAndWait to work as advertised

changes:
* extract shutdown setup to a func and call it from both start and startAndWait
* add test
* fix api doc
* fixi jazzy xenial issue (fixes ci)
2020-08-08 20:27:20 -07: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 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 a22bf0b3be refactor towards 1.0 (#34)
motivation: finalize naming and API towards 1.0

changes:
* rename package to swift-service-boostrap
* rename modules to Lifecycle and LifecycleNIOCompat
* create top level namespace named Lifecycle
* rename LifecycleItem to LifecycleTask, with Lifecycle.Task typealias
* define top-level type called ServiceLifecycle where signal handling and backtraces are handled
* rename Lifecycle to ComponentLifecycle and conform it to Lifecycle.Task so that lifecycles can be nested
* change shutdown to return an error to better conform with Lifecycle.Task api
* improve logging
* improve API docs
* adjust tests
2020-04-09 21:15:22 -07:00
tomer doron 35ea48e628 update ci setup (#24)
motivation: 5.2 adoption, prepare for 5.3

changes:
* use 5.2 release in docker-compose setup
* add 5.3 docker-compose setup (placeholder)
* format
2020-04-03 19:51:07 -07:00
tomer doron ed61383431 formatting (#5)
motivation: align format versioning

changes:
* set explicit target language version to the lowest supported swift version
* update swiftformat version
2020-03-20 12:45:06 -07:00
Tom Doron 1abe527c92 initial commit 2020-03-18 11:56:30 -07:00