Commit Graph
35 Commits
Author SHA1 Message Date
Konrad `ktoso` Malawski 4755d7fc1e Fix availability annotations to include platforms 2022-06-22 17:38:49 +09:00
tomer doron 2744df51f9 unless shutdownIfNotStarted is set to true, dont shutdown items that failed to start (#107)
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
2021-09-03 23:17:55 -07:00
tomer doron c825a58490 shutdown any task that have shutdownIfNotStarted set to true when shutting down a never-started-lifecycle (#109)
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
2021-09-02 08:48:04 -07:00
tomer doron 66fb9c089b fix repeated shutdown issue on linux (#104)
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
2021-08-19 17:23:03 -07:00
tomer doron 84d2bc37d7 adjust to updated concurrency API (#102) 2021-06-09 19:00:28 -07:00
tomer doron 7f70674c22 add handlers that support async functions (#99)
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
2021-05-12 21:41:15 -07:00
Moritz Lang 103c143d52 Remove [Lifecycle] prefix from log messages (#95)
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.
2021-05-04 11:58:13 +09:00
tomer doron 4714c3cdfa add lifecycle metrics (#93)
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
2021-03-18 11:39:26 -07:00
tomer doron 5577147e4e make the underlying component lifecycle private again (#91)
* 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
2021-03-18 09:12:50 +09:00
Fabian Fett e5e078d534 Import Atomics @_implementationOnly (#89) 2021-03-17 13:52:57 -07:00
tomer doron 8b5c377ae3 Revert "Install shutdown signal hooks as LifecycleTask (#88)" (#90)
motivation: start handlers should not actually be part of the initialization process, as it breaks composition between ServiceLifecycles

changes: This reverts commit dce53aa6f2.
2021-03-17 12:54:27 -07:00
Joakim Hassila dce53aa6f2 Install shutdown signal hooks as LifecycleTask (#88)
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.
2021-03-16 12:18:57 -07:00
tomer doron e6b78a807b add support for stateful handler (#84)
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
2021-03-13 11:29:28 -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
Joakim Hassila ac8ba89a91 Add support for HUP, USR1, USR2 signals (#86)
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.
2021-03-12 20:42:54 -08:00
tomer doron 272d1f589f expose shutdownIfNotStarted argument on regsiter (#83)
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
2021-03-10 17:42:01 -08:00
tomer doron a7356e142b add semantics for stopping tasks that have no start handler (#77)
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
2020-10-26 16:12:50 -07:00
tomer doron 3a02d48c95 abstract registration functions into a protocol (#75)
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
2020-09-26 16:42:20 -07:00
adfec6ae94 API docs cleanup and other minor fixes (#73)
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>
2020-09-01 14:43:57 -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
Alessio Buratti eb685b6fa1 Update ServiceLifecycle.Configuration comments (#58)
It seems to me that the comments of shutdownSignal and installBacktrace were inverted, I apologize in advance if I misunderstood something.
2020-07-17 11:20:46 -07:00
YR Chen 5ad999203c Allow zero-task startup (#55)
* Allow zero-task startup

* Add test for zero-task

* Fix Linux build and improve consistency

* Fix sanity
2020-07-17 12:28:22 +09:00
YR Chenandtomer doron 945d681aee Fix typo (#56)
Co-authored-by: tomer doron <tomerd@apple.com>
2020-07-16 18:07:36 -07:00
Alexander Cyon 6742fc4ce8 fix typo (#48) 2020-07-16 07:41:53 -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 b5ead647f9 remove closure variants to reduce API confusion (#46)
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
2020-07-14 10:01:19 -07:00
Konrad `ktoso` Malawski 2891ee74b6 Slightly nicer string description for Signal (#42)
* Slightly nicer string description for Signal
* compat with swift before 5.3
2020-06-26 08:56:58 -07:00
tomer doron 19c52240e6 update api to remove Lifecycle psuedo namespace (#40)
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
2020-05-27 19:20:26 -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 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 070734a734 rename module (#12)
motivation: adjust module name to avoid ambiguity between module and main type

changes: rename Lifecycle to ServiceLauncher
2020-03-31 20:08:32 -07:00
tomer doron ae96513515 add default config (#7)
motivation: make API easier to use

changes: add default value to configuraiton argument
2020-03-27 16:27:28 -07:00
tomer doron 46a98e2852 refactor "append" api (#3)
motivation: simplify registering items based on closures

changes:
* rename append to register
* introduce a Handler object that is an enum of sorts for types of startup and shutdown handler signature we support
* refactor tests to use the new code
2020-03-23 11:35:55 -07:00
tomer doron e7ec8da443 remove deprecated methods (#4)
motivation: no need in deprecated methods since we did not tag yet

changes: remove deprecated start and startAndWait methods
2020-03-19 20:37:11 -07:00
Tom Doron 1abe527c92 initial commit 2020-03-18 11:56:30 -07:00