15
15
import Logging
16
16
import UnixSignals
17
17
18
- /// A ``ServiceRunner`` is responsible for running a number of services, setting up signal handling and shutting down services in the correct order .
18
+ /// A ``ServiceRunner`` is responsible for running a number of services, setting up signal handling and signalling graceful shutdown to the services .
19
19
public actor ServiceRunner : Sendable {
20
20
/// The internal state of the ``ServiceRunner``.
21
21
private enum State {
@@ -128,8 +128,6 @@ public actor ServiceRunner: Sendable {
128
128
}
129
129
}
130
130
131
- var finishedServiceCount = 0
132
-
133
131
// We are going to wait for any of the services to finish or
134
132
// the signal sequence to throw an error.
135
133
while !group. isEmpty {
@@ -138,41 +136,17 @@ public actor ServiceRunner: Sendable {
138
136
139
137
switch result {
140
138
case . serviceFinished( let service) :
141
- if service. isLongRunning {
142
- // If a long running service finishes early we treat this as an unexpected
143
- // early exit and have to cancel the rest of the services.
144
- self . logger. error (
145
- " Service finished unexpectedly " ,
146
- metadata: [
147
- self . configuration. logging. serviceKey: " \( service) " ,
148
- ]
149
- )
150
-
151
- group. cancelAll ( )
152
- return . failure( ServiceRunnerError . serviceFinishedUnexpectedly ( ) )
153
- } else {
154
- // This service finished early but we expected it.
155
- // So we are just going to wait for the next service
156
- self . logger. debug (
157
- " Service finished " ,
158
- metadata: [
159
- self . configuration. logging. serviceKey: " \( service) " ,
160
- ]
161
- )
162
-
163
- // We have to keep track of how many services finished to make sure
164
- // to stop when only the signal child task is left
165
- finishedServiceCount += 1
166
- if finishedServiceCount == self . services. count {
167
- // Every service finished. We can cancel the signal handling now
168
- // and return
169
- group. cancelAll ( )
170
- return . success( ( ) )
171
- } else {
172
- // There are still running services that we have to wait for
173
- continue
174
- }
175
- }
139
+ // If a long running service finishes early we treat this as an unexpected
140
+ // early exit and have to cancel the rest of the services.
141
+ self . logger. error (
142
+ " Service finished unexpectedly " ,
143
+ metadata: [
144
+ self . configuration. logging. serviceKey: " \( service) " ,
145
+ ]
146
+ )
147
+
148
+ group. cancelAll ( )
149
+ return . failure( ServiceRunnerError . serviceFinishedUnexpectedly ( ) )
176
150
177
151
case . serviceThrew( let service, let error) :
178
152
// One of the servers threw an error. We have to cancel everything else now.
0 commit comments