motivation: improve confusing behavior
changes:
* change startTask to return an array of started tasks instead of an index
* only shutdown successfully started tasks or ones that have explicitly set shutdownIfNotStarted to true
* add and adjust tests
motivation: more reliable shutdown in edge cases where lifecycle never gets started
changes: when shutting down an idle lifecycle, try to shutdown any tasks that have shutdownIfNotStarted set to true
motivation: repeatedly calling shutdown in linux was broken due to multiple calls to singal() which work on darwin but not linux
changes:
* conditionalize the call to signal to once per process
* add test
motivation: async/await is coming in 5.5, take first steps to support it
changes:
* introduce handler initializers that takes async functions (@escaping () async throws -> Void, @escaping () async throws -> State)
* add tests
Motivation:
Since Swift Log 1.3.0, log handlers can include the source of a particular message,
rendering the [Lifecycle] prefix unnecessary.
Modifications:
Removed the [Lifecycle] prefix from all log messages by removing the underlying
log helper and calling out to the Logger itself.
Result:
Log messages written by a log handler which includes the location wont log "Lifecycle" twice.
motivation: startup/shutdown metrics are important for real-life services, for example spike in start metrics indicates a crash-loop
changes:
* add start and shutdown counters to ComponentLifecycle
* add start and shutdown timers to report duration of startup and shutdown operations
* make the underlying component lifecycle private again
motivation: there is no need to explose the underlying component lifecycle, since there are better composition solutions
changets: make ServiceLifecycle::underlying private (again)
* fixup
motivation: start handlers should not actually be part of the initialization process, as it breaks composition between ServiceLifecycles
changes: This reverts commit dce53aa6f2.
Motivation:
Small code cleanup, reusing LifecycleTask as the shutdown hooks are
to be installed just at the beginning of that chain of events anyway.
Modifications:
Moved signal handler installation to LifecycleTask instead of direct calls.
Result:
Slightly simpler code.
motivation: allow lifecycle handlers to have the library manage the state for them so they do not need to do that manually
changes:
* introduce LifecycleStartHandler and LifecycleShutdownHandler which can handle state on behalf of the lifecycle item
* add registerStateful function to regsiter stateful handlers
* add tests
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)
Motivation:
Adding support for capturing HUP too in addition to USR1/USR2.
Modifications:
* Added HUP signal, added descriptive strings for new signals.
* Optionally allow to let signal handler run multiple times, useful for USR signals
Result:
HUP and USR signals available.
motivation: in some cases, users want to force shutdown even if start never called, for example if the library asserts for shutdown regardless of start
changes: expose shutdownIfNotStarted on regsiter function
motivation: address shutdown for tasks which allocate resources on construction. before this change, only tasks that have been started are shutdown, this creates an issue when the resources are allocated on construction since the item may not get started at all (for example due to error in earlier task) and thus will never be shutdown and the resources will leak.
changes: add sematics to request shutdown even if not started, and assume this sematics when registering with start: .none or with registerShutdown
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
motivation: allow frameworks that want to expose the lifecycle so that their downstream dependencies could register additional items
changes: abstract registration functions into a protocol and conform ComponentLifecycle and ServiceLifecycle to it
motivation: better API docs and usability
changes:
* allow customization of ServiceLifecycle label
* adjust APi docs
* fix tests on macOS (availability)
Co-authored-by: Yim Lee <yim_lee@apple.com>
Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
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)
The README.md only listed 3 of the 4 Configuration options and did not mention the logging option.
Added logging option to the configuration discussion.
Placed it first, which is the same as the argument order for ServiceLifecycle.Configuration.
motivation:
API now includes closure based variants, saving the need to wrap them in .sync
Users have complained that these overloads add confusion, and probably not worth the additional API surface area
changes:
* remove the sync closure API overloads
* update readme, examples and tests
motivation: address api feedback, do not clash module and type names
changes:
* remove top level Lifecycle psuedo namespace (enum)
* rename Lifecycle.Task to LifecyclTask
* rename Lifecycle.Handler to LifecycleHandler