@@ -43,7 +43,12 @@ class RapidApplication internal constructor(
43
43
}
44
44
}
45
45
46
- override fun onMessage (message : String , context : MessageContext , metadata : MessageMetadata , meterRegistry : MeterRegistry ) {
46
+ override fun onMessage (
47
+ message : String ,
48
+ context : MessageContext ,
49
+ metadata : MessageMetadata ,
50
+ meterRegistry : MeterRegistry
51
+ ) {
47
52
notifyMessage(message, context, metadata, meterRegistry)
48
53
}
49
54
@@ -54,11 +59,7 @@ class RapidApplication internal constructor(
54
59
rapid.start()
55
60
} finally {
56
61
onKtorShutdown()
57
- val gracePeriod = 5000L
58
- val forcefulShutdownTimeout = 30000L
59
- log.info(" shutting down ktor, waiting $gracePeriod ms for workers to exit. Forcing shutdown after $forcefulShutdownTimeout ms" )
60
- ktor.stop(gracePeriod, forcefulShutdownTimeout)
61
- log.info(" ktor shutdown complete: end of life. goodbye." )
62
+ log.info(" shutdown complete: end of life. goodbye." )
62
63
}
63
64
}
64
65
@@ -113,16 +114,20 @@ class RapidApplication internal constructor(
113
114
log.info(" publishing $event event for app_name=$appName , instance_id=$instanceId " )
114
115
try {
115
116
rapidsConnection.publish(it)
116
- } catch (err: Exception ) { log.info(" failed to publish event: {}" , err.message, err) }
117
+ } catch (err: Exception ) {
118
+ log.info(" failed to publish event: {}" , err.message, err)
119
+ }
117
120
}
118
121
}
119
122
120
123
private fun applicationEvent (event : String ): String? {
121
124
if (appName == null ) return null
122
- val packet = JsonMessage .newMessage(event, mapOf (
123
- " app_name" to appName,
124
- " instance_id" to instanceId
125
- ))
125
+ val packet = JsonMessage .newMessage(
126
+ event, mapOf (
127
+ " app_name" to appName,
128
+ " instance_id" to instanceId
129
+ )
130
+ )
126
131
return packet.toJson()
127
132
}
128
133
@@ -132,7 +137,11 @@ class RapidApplication internal constructor(
132
137
fun create (
133
138
env : Map <String , String >,
134
139
consumerProducerFactory : ConsumerProducerFactory = ConsumerProducerFactory (AivenConfig .default),
135
- meterRegistry : PrometheusMeterRegistry = PrometheusMeterRegistry (PrometheusConfig .DEFAULT , PrometheusRegistry .defaultRegistry, Clock .SYSTEM ),
140
+ meterRegistry : PrometheusMeterRegistry = PrometheusMeterRegistry (
141
+ PrometheusConfig .DEFAULT ,
142
+ PrometheusRegistry .defaultRegistry,
143
+ Clock .SYSTEM
144
+ ),
136
145
builder : Builder .() -> Unit = {},
137
146
configure : (EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >, KafkaRapid ) -> Unit = { _, _ -> }
138
147
): RapidsConnection {
@@ -157,9 +166,15 @@ class RapidApplication internal constructor(
157
166
}
158
167
159
168
private fun generateAppName (env : Map <String , String >): String? {
160
- val appName = env[" NAIS_APP_NAME" ] ? : return log.info(" not generating app name because NAIS_APP_NAME not set" ).let { null }
161
- val namespace = env[" NAIS_NAMESPACE" ] ? : return log.info(" not generating app name because NAIS_NAMESPACE not set" ).let { null }
162
- val cluster = env[" NAIS_CLUSTER_NAME" ] ? : return log.info(" not generating app name because NAIS_CLUSTER_NAME not set" ).let { null }
169
+ val appName =
170
+ env[" NAIS_APP_NAME" ] ? : return log.info(" not generating app name because NAIS_APP_NAME not set" )
171
+ .let { null }
172
+ val namespace =
173
+ env[" NAIS_NAMESPACE" ] ? : return log.info(" not generating app name because NAIS_NAMESPACE not set" )
174
+ .let { null }
175
+ val cluster =
176
+ env[" NAIS_CLUSTER_NAME" ] ? : return log.info(" not generating app name because NAIS_CLUSTER_NAME not set" )
177
+ .let { null }
163
178
return " $appName -$cluster -$namespace "
164
179
}
165
180
}
@@ -191,9 +206,10 @@ class RapidApplication internal constructor(
191
206
this .ktor = ktor
192
207
}
193
208
194
- fun withKtor (ktor : (PreStopHook , KafkaRapid ) -> EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >) = apply {
195
- this .ktor = ktor(stopHook, rapid)
196
- }
209
+ fun withKtor (ktor : (PreStopHook , KafkaRapid ) -> EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >) =
210
+ apply {
211
+ this .ktor = ktor(stopHook, rapid)
212
+ }
197
213
198
214
fun withKtorModule (module : Application .() -> Unit ) = apply {
199
215
this .modules.add(module)
@@ -223,7 +239,10 @@ class RapidApplication internal constructor(
223
239
naisEndpoints = naisEndpoints.copy(preStopEndpoint = preStopHookEndpoint)
224
240
}
225
241
226
- fun build (configure : (EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >, KafkaRapid ) -> Unit = { _, _ -> }, cioConfiguration : CIOApplicationEngine .Configuration .() -> Unit = { } ): RapidsConnection {
242
+ fun build (
243
+ configure : (EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >, KafkaRapid ) -> Unit = { _, _ -> },
244
+ cioConfiguration : CIOApplicationEngine .Configuration .() -> Unit = { }
245
+ ): RapidsConnection {
227
246
val app = ktor ? : defaultKtorApp(cioConfiguration)
228
247
configure(app, rapid)
229
248
with (meterRegistry) {
0 commit comments