Skip to content

Commit daa5eae

Browse files
committed
core: extend use of osrdErrorType.isRecoverable
Improve the expressiveness when handling exceptions in rabbit worker. After #10594 and #9439. Also minor code/log improvements. Signed-off-by: Pierre-Etienne Bougué <[email protected]>
1 parent 8383e44 commit daa5eae

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

core/src/main/java/fr/sncf/osrd/cli/WorkerCommand.kt

+16-11
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,18 @@ class WorkerCommand : CliCommand {
154154
try {
155155
infraManager.load(infraId, null, diagnosticRecorder)
156156
} catch (e: OSRDError) {
157-
if (e.osrdErrorType == ErrorType.InfraHardLoadingError) {
158-
logger.warn("Failed to load infra $infraId with a perennial error: $e")
159-
// go on and future requests will be consumed and rejected
160-
} else if (e.osrdErrorType == ErrorType.InfraSoftLoadingError) {
161-
logger.error("Failed to load infra $infraId with a temporary error: $e")
162-
// Stop worker and let another worker spawn eventually
163-
throw e
157+
val isInfraLoadError =
158+
setOf(ErrorType.InfraHardLoadingError, ErrorType.InfraSoftLoadingError)
159+
.contains(e.osrdErrorType)
160+
if (isInfraLoadError) {
161+
if (e.osrdErrorType.isRecoverable) {
162+
logger.warn("Failed to load infra $infraId with a perennial error: $e")
163+
// go on and future requests will be consumed and rejected
164+
} else {
165+
logger.error("Failed to load infra $infraId with a temporary error: $e")
166+
// Stop worker and let another worker spawn eventually
167+
throw e
168+
}
164169
} else {
165170
logger.error(
166171
"Failed to load infra $infraId with an unexpected OSRD Error: $e"
@@ -268,7 +273,7 @@ class WorkerCommand : CliCommand {
268273
.toByteArray() // TODO: have a valid payload for uncaught exceptions
269274
status = "core_error".encodeToByteArray()
270275
// Stop worker and let another worker spawn eventually
271-
if (t is OSRDError && t.osrdErrorType == ErrorType.InfraSoftLoadingError) {
276+
if (t is OSRDError && !t.osrdErrorType.isRecoverable) {
272277
throw t
273278
}
274279
} finally {
@@ -308,7 +313,7 @@ class WorkerCommand : CliCommand {
308313
WORKER_REQUESTS_QUEUE,
309314
false,
310315
mapOf(),
311-
DeliverCallback { _, message ->
316+
{ _, message ->
312317
if (executor.queue.count() >= WORKER_THREADS * 4) {
313318
// We directly process the message with no dispatch if there's too many
314319
// locally queued tasks. Prevents the worker from consuming all the rabbitmq
@@ -327,13 +332,13 @@ class WorkerCommand : CliCommand {
327332
}
328333
)
329334

330-
logger.info("consume ended")
331-
332335
while (true) {
333336
Thread.sleep(100)
334337
if (!channel.isOpen()) break
335338
}
336339

340+
logger.info("consume ended")
341+
337342
return 0
338343
}
339344
}

0 commit comments

Comments
 (0)