diff --git a/common/src/main/scala/com/lbs/common/Scheduler.scala b/common/src/main/scala/com/lbs/common/Scheduler.scala index ea55c6a..ffc8a22 100644 --- a/common/src/main/scala/com/lbs/common/Scheduler.scala +++ b/common/src/main/scala/com/lbs/common/Scheduler.scala @@ -27,7 +27,7 @@ import java.util.concurrent.{Executors, ScheduledFuture} import scala.concurrent.duration.FiniteDuration -class Scheduler(poolSize: Int) { +class Scheduler(poolSize: Int) extends Logger { private val scheduledThreadPool = Executors.newScheduledThreadPool(poolSize) def schedule(fn: => Unit, period: FiniteDuration): ScheduledFuture[_] = { @@ -36,6 +36,16 @@ class Scheduler(poolSize: Int) { def schedule(fn: => Unit, delay: FiniteDuration, period: FiniteDuration): ScheduledFuture[_] = { require(delay.unit == period.unit, s"Delay units must be the same as for period ${period.unit}") - scheduledThreadPool.scheduleAtFixedRate(() => fn, delay.length, period.length, period.unit) + scheduledThreadPool.scheduleAtFixedRate(silentFn(fn), delay.length, period.length, period.unit) + } + + private def silentFn(fn: => Unit): Runnable = { + () => + try { + fn + } catch { + case ex: Exception => + LOG.error(s"Unable to execute scheduler task", ex) + } } } diff --git a/server/src/main/scala/com/lbs/server/service/MonitoringService.scala b/server/src/main/scala/com/lbs/server/service/MonitoringService.scala index dfa1dcc..77b202e 100644 --- a/server/src/main/scala/com/lbs/server/service/MonitoringService.scala +++ b/server/src/main/scala/com/lbs/server/service/MonitoringService.scala @@ -1,26 +1,26 @@ /** - * MIT License - * - * Copyright (c) 2018 Yevhen Zadyra - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ + * MIT License + * + * Copyright (c) 2018 Yevhen Zadyra + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package com.lbs.server.service import java.time.ZonedDateTime