Commit Graph
22 Commits
Author SHA1 Message Date
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 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
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 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
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
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
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 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 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 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
Tom Doron 1abe527c92 initial commit 2020-03-18 11:56:30 -07:00