mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-21 13:23:05 +01:00
Fixed typos, updated readme refactored logger
This commit is contained in:
@@ -26,7 +26,7 @@ It is available by [@luxmedbot](https://telegram.me/luxmedbot)
|
|||||||
- install postgres and create db **lbs** with login **lbs** and password **lsb123**
|
- install postgres and create db **lbs** with login **lbs** and password **lsb123**
|
||||||
- run using `./gradlew bootRun`
|
- run using `./gradlew bootRun`
|
||||||
|
|
||||||
5. send `/start` to your bot
|
5. send `/start` command to your bot
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ package object http extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def toTry: Try[HttpResponse[String]] = {
|
def toTry: Try[HttpResponse[String]] = {
|
||||||
LOG.debug(s"Sending request:\n${hidePasswords(httpRequest)}")
|
debug(s"Sending request:\n${hidePasswords(httpRequest)}")
|
||||||
val httpResponse = Try(httpRequest.asString)
|
val httpResponse = Try(httpRequest.asString)
|
||||||
LOG.debug(s"Received response:\n$httpResponse")
|
debug(s"Received response:\n$httpResponse")
|
||||||
extractLuxmedError(httpResponse) match {
|
extractLuxmedError(httpResponse) match {
|
||||||
case Some(error) => Try(throw error)
|
case Some(error) => Try(throw error)
|
||||||
case None => httpResponse.map(_.throwError)
|
case None => httpResponse.map(_.throwError)
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ class TelegramClient(onReceive: TelegramEvent => Unit, botToken: String) extends
|
|||||||
|
|
||||||
|
|
||||||
override def receiveMessage(msg: Message): Unit = {
|
override def receiveMessage(msg: Message): Unit = {
|
||||||
LOG.debug(s"Received telegram message: $msg")
|
debug(s"Received telegram message: $msg")
|
||||||
onReceive(TelegramEvent(msg, None))
|
onReceive(TelegramEvent(msg, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
onCallbackWithTag(TagPrefix) { implicit cbq =>
|
onCallbackWithTag(TagPrefix) { implicit cbq =>
|
||||||
LOG.debug(s"Received telegram callback: $cbq")
|
debug(s"Received telegram callback: $cbq")
|
||||||
ackCallback()
|
ackCallback()
|
||||||
for {
|
for {
|
||||||
data <- cbq.data.map(_.stripPrefix(TagPrefix))
|
data <- cbq.data.map(_.stripPrefix(TagPrefix))
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
/**
|
/**
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2018 Yevhen Zadyra
|
* Copyright (c) 2018 Yevhen Zadyra
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
* copies or substantial portions of the Software.
|
* copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package com.lbs.common
|
package com.lbs.common
|
||||||
|
|
||||||
import org.slf4j
|
import org.slf4j
|
||||||
@@ -29,38 +29,34 @@ import org.slf4j.LoggerFactory
|
|||||||
trait Logger {
|
trait Logger {
|
||||||
private val log: slf4j.Logger = LoggerFactory.getLogger(this.getClass)
|
private val log: slf4j.Logger = LoggerFactory.getLogger(this.getClass)
|
||||||
|
|
||||||
protected val LOG = new LoggerWrapper
|
def debug(msg: => String): Unit = {
|
||||||
|
if (log.isDebugEnabled)
|
||||||
|
log.debug(msg)
|
||||||
|
}
|
||||||
|
|
||||||
class LoggerWrapper {
|
def warn(msg: => String): Unit = {
|
||||||
def debug(msg: => String): Unit = {
|
if (log.isWarnEnabled)
|
||||||
if (log.isDebugEnabled)
|
log.warn(msg)
|
||||||
log.debug(msg)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
def warn(msg: => String): Unit = {
|
def warn(msg: => String, throwable: Throwable): Unit = {
|
||||||
if (log.isWarnEnabled)
|
if (log.isWarnEnabled)
|
||||||
log.warn(msg)
|
log.warn(msg, throwable)
|
||||||
}
|
}
|
||||||
|
|
||||||
def warn(msg: => String, throwable: Throwable): Unit = {
|
def error(msg: => String): Unit = {
|
||||||
if (log.isWarnEnabled)
|
if (log.isErrorEnabled)
|
||||||
log.warn(msg, throwable)
|
log.error(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
def error(msg: => String): Unit = {
|
def error(msg: => String, throwable: Throwable): Unit = {
|
||||||
if (log.isErrorEnabled)
|
if (log.isErrorEnabled)
|
||||||
log.error(msg)
|
log.error(msg, throwable)
|
||||||
}
|
}
|
||||||
|
|
||||||
def error(msg: => String, throwable: Throwable): Unit = {
|
def info(msg: => String): Unit = {
|
||||||
if (log.isErrorEnabled)
|
if (log.isInfoEnabled)
|
||||||
log.error(msg, throwable)
|
log.info(msg)
|
||||||
}
|
|
||||||
|
|
||||||
def info(msg: => String): Unit = {
|
|
||||||
if (log.isInfoEnabled)
|
|
||||||
log.info(msg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class Scheduler(poolSize: Int) extends Logger {
|
|||||||
fn
|
fn
|
||||||
} catch {
|
} catch {
|
||||||
case ex: Exception =>
|
case ex: Exception =>
|
||||||
LOG.error(s"Unable to execute scheduler task", ex)
|
error(s"Unable to execute scheduler task", ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class Account(val userId: UserId, bot: Bot, dataService: DataService, val locali
|
|||||||
}
|
}
|
||||||
goto(AskAction) using null
|
goto(AskAction) using null
|
||||||
case None =>
|
case None =>
|
||||||
LOG.error(s"This is not user [#${userId.userId}] account [#$accountId]")
|
error(s"This is not user [#${userId.userId}] account [#$accountId]")
|
||||||
goto(AskAction) using null
|
goto(AskAction) using null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ class Account(val userId: UserId, bot: Bot, dataService: DataService, val locali
|
|||||||
invokeNext()
|
invokeNext()
|
||||||
goto(AskAction) using null
|
goto(AskAction) using null
|
||||||
case e: Event =>
|
case e: Event =>
|
||||||
LOG.error(s"Unhandled event in state:$stateName. Event: $e")
|
error(s"Unhandled event in state:$stateName. Event: $e")
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,11 +229,11 @@ class Book(val userId: UserId, bot: Bot, apiService: ApiService, dataService: Da
|
|||||||
|
|
||||||
whenSafe(CreateMonitoring) {
|
whenSafe(CreateMonitoring) {
|
||||||
case Event(Next, bookingData: BookingData) =>
|
case Event(Next, bookingData: BookingData) =>
|
||||||
LOG.debug(s"Creating monitoring for $bookingData")
|
debug(s"Creating monitoring for $bookingData")
|
||||||
Try(monitoringService.createMonitoring((userId -> bookingData).mapTo[Monitoring])) match {
|
Try(monitoringService.createMonitoring((userId -> bookingData).mapTo[Monitoring])) match {
|
||||||
case Success(_) => bot.sendMessage(userId.source, lang.monitoringHasBeenCreated)
|
case Success(_) => bot.sendMessage(userId.source, lang.monitoringHasBeenCreated)
|
||||||
case Failure(ex) =>
|
case Failure(ex) =>
|
||||||
LOG.error("Unable to create monitoring", ex)
|
error("Unable to create monitoring", ex)
|
||||||
bot.sendMessage(userId.source, lang.unableToCreateMonitoring)
|
bot.sendMessage(userId.source, lang.unableToCreateMonitoring)
|
||||||
}
|
}
|
||||||
goto(RequestCity) using BookingData()
|
goto(RequestCity) using BookingData()
|
||||||
@@ -243,7 +243,7 @@ class Book(val userId: UserId, bot: Bot, apiService: ApiService, dataService: Da
|
|||||||
case Event(Init, _) =>
|
case Event(Init, _) =>
|
||||||
reinit()
|
reinit()
|
||||||
case e: Event =>
|
case e: Event =>
|
||||||
LOG.error(s"Unhandled event in state:$stateName. Event: $e")
|
error(s"Unhandled event in state:$stateName. Event: $e")
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class Chat(val userId: UserId, dataService: DataService, monitoringService: Moni
|
|||||||
|
|
||||||
whenUnhandledSafe {
|
whenUnhandledSafe {
|
||||||
case e: Event =>
|
case e: Event =>
|
||||||
LOG.debug(s"Unhandled event in state:$stateName. Event: $e")
|
debug(s"Unhandled event in state:$stateName. Event: $e")
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class DatePicker(val userId: UserId, val bot: Bot, val localization: Localizatio
|
|||||||
case Event(Init, _) =>
|
case Event(Init, _) =>
|
||||||
goto(AwaitMode) using null
|
goto(AwaitMode) using null
|
||||||
case e: Event =>
|
case e: Event =>
|
||||||
LOG.error(s"Unhandled event in state:$stateName. Event: $e")
|
error(s"Unhandled event in state:$stateName. Event: $e")
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class Login(source: MessageSource, bot: Bot, dataService: DataService, apiServic
|
|||||||
case Event(Init, _) =>
|
case Event(Init, _) =>
|
||||||
goto(LogIn) using LoginData()
|
goto(LogIn) using LoginData()
|
||||||
case e: Event =>
|
case e: Event =>
|
||||||
LOG.error(s"Unhandled event in state:$stateName. Event: $e")
|
error(s"Unhandled event in state:$stateName. Event: $e")
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class Pager[Data](val userId: UserId, bot: Bot, makeMessage: (Data, Int, Int) =>
|
|||||||
case Event(Init, _) =>
|
case Event(Init, _) =>
|
||||||
goto(PrepareData) using null
|
goto(PrepareData) using null
|
||||||
case e: Event =>
|
case e: Event =>
|
||||||
LOG.error(s"Unhandled event in state:$stateName. Event: $e")
|
error(s"Unhandled event in state:$stateName. Event: $e")
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class Router(authActorFactory: ByMessageSourceActorFactory) extends Actor with L
|
|||||||
destroyChat(source)
|
destroyChat(source)
|
||||||
case SwitchUser(userId) =>
|
case SwitchUser(userId) =>
|
||||||
switchUser(userId)
|
switchUser(userId)
|
||||||
case what => LOG.info(s"Unknown message: $what")
|
case what => info(s"Unknown message: $what")
|
||||||
}
|
}
|
||||||
|
|
||||||
private def addNewChatActor(source: MessageSource): ActorRef = {
|
private def addNewChatActor(source: MessageSource): ActorRef = {
|
||||||
@@ -65,7 +65,7 @@ class Router(authActorFactory: ByMessageSourceActorFactory) extends Actor with L
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def destroyChat(source: MessageSource): Unit = {
|
private def destroyChat(source: MessageSource): Unit = {
|
||||||
LOG.info(s"Destroying chat for $source due to $idleTimeout inactivity")
|
info(s"Destroying chat for $source due to $idleTimeout of inactivity")
|
||||||
timers.remove(source)
|
timers.remove(source)
|
||||||
removeChat(source)
|
removeChat(source)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ trait SafeFSM[S, D] extends FSM[S, D] with Logger {
|
|||||||
|
|
||||||
protected val defaultEventHandler: StateFunction = {
|
protected val defaultEventHandler: StateFunction = {
|
||||||
case e: Event =>
|
case e: Event =>
|
||||||
LOG.warn(s"Unhandled event in state:$stateName. Event: $e")
|
warn(s"Unhandled event in state:$stateName. Event: $e")
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ trait SafeFSM[S, D] extends FSM[S, D] with Logger {
|
|||||||
else eventHandler(event)
|
else eventHandler(event)
|
||||||
} catch {
|
} catch {
|
||||||
case e: Exception =>
|
case e: Exception =>
|
||||||
LOG.error(s"Exception occurred while processing event $event", e)
|
error(s"Exception occurred while processing event $event", e)
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class StaticData(val userId: UserId, bot: Bot, val localization: Localization, o
|
|||||||
case Event(Init, _) =>
|
case Event(Init, _) =>
|
||||||
goto(AwaitConfig) using null
|
goto(AwaitConfig) using null
|
||||||
case e: Event =>
|
case e: Event =>
|
||||||
LOG.error(s"Unhandled event in state:$stateName. Event: $e")
|
error(s"Unhandled event in state:$stateName. Event: $e")
|
||||||
stay()
|
stay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,14 +88,14 @@ class MonitoringService extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def monitor(monitoring: Monitoring): Unit = {
|
private def monitor(monitoring: Monitoring): Unit = {
|
||||||
LOG.debug(s"Looking for available terms. Monitoring [#${monitoring.recordId}]")
|
debug(s"Looking for available terms. Monitoring [#${monitoring.recordId}]")
|
||||||
val dateFrom = optimizeDateFrom(monitoring.dateFrom)
|
val dateFrom = optimizeDateFrom(monitoring.dateFrom)
|
||||||
val termsEither = apiService.getAvailableTerms(monitoring.accountId, monitoring.cityId, monitoring.clinicId, monitoring.serviceId,
|
val termsEither = apiService.getAvailableTerms(monitoring.accountId, monitoring.cityId, monitoring.clinicId, monitoring.serviceId,
|
||||||
monitoring.doctorId, dateFrom, Some(monitoring.dateTo))
|
monitoring.doctorId, dateFrom, Some(monitoring.dateTo))
|
||||||
termsEither match {
|
termsEither match {
|
||||||
case Right(terms) =>
|
case Right(terms) =>
|
||||||
if (terms.nonEmpty) {
|
if (terms.nonEmpty) {
|
||||||
LOG.debug(s"Found ${terms.length} terms by monitoring [#${monitoring.recordId}]")
|
debug(s"Found ${terms.length} terms by monitoring [#${monitoring.recordId}]")
|
||||||
if (monitoring.autobook) {
|
if (monitoring.autobook) {
|
||||||
val term = terms.head
|
val term = terms.head
|
||||||
bookAppointment(term, monitoring)
|
bookAppointment(term, monitoring)
|
||||||
@@ -103,16 +103,16 @@ class MonitoringService extends Logger {
|
|||||||
notifyUserAboutTerms(terms, monitoring)
|
notifyUserAboutTerms(terms, monitoring)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.debug(s"No new terms found for monitoring [#${monitoring.recordId}]")
|
debug(s"No new terms found for monitoring [#${monitoring.recordId}]")
|
||||||
}
|
}
|
||||||
case Left(ex: InvalidLoginOrPasswordException) =>
|
case Left(ex: InvalidLoginOrPasswordException) =>
|
||||||
LOG.error(s"User entered invalid name or password. Monitoring will be disabled", ex)
|
error(s"User entered invalid name or password. Monitoring will be disabled", ex)
|
||||||
bot.sendMessage(monitoring.source, lang(monitoring.userId).invalidLoginOrPassword)
|
bot.sendMessage(monitoring.source, lang(monitoring.userId).invalidLoginOrPassword)
|
||||||
val activeUserMonitorings = dataService.getActiveMonitorings(monitoring.accountId)
|
val activeUserMonitorings = dataService.getActiveMonitorings(monitoring.accountId)
|
||||||
activeUserMonitorings.foreach { m =>
|
activeUserMonitorings.foreach { m =>
|
||||||
deactivateMonitoring(m.recordId)
|
deactivateMonitoring(m.recordId)
|
||||||
}
|
}
|
||||||
case Left(ex) => LOG.error(s"Unable to receive terms by monitoring [#${monitoring.recordId}]", ex)
|
case Left(ex) => error(s"Unable to receive terms by monitoring [#${monitoring.recordId}]", ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,17 +127,17 @@ class MonitoringService extends Logger {
|
|||||||
val delaySnapshot = delay
|
val delaySnapshot = delay
|
||||||
val periodSnapshot = period
|
val periodSnapshot = period
|
||||||
val future = monitoringExecutor.schedule(monitor(monitoring), delaySnapshot, periodSnapshot)
|
val future = monitoringExecutor.schedule(monitor(monitoring), delaySnapshot, periodSnapshot)
|
||||||
LOG.debug(s"Scheduled monitoring: [#${monitoring.recordId}] with delay: $delaySnapshot and period: $periodSnapshot")
|
debug(s"Scheduled monitoring: [#${monitoring.recordId}] with delay: $delaySnapshot and period: $periodSnapshot")
|
||||||
activeMonitorings += (monitoring.recordId -> (monitoring -> future))
|
activeMonitorings += (monitoring.recordId -> (monitoring -> future))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def initializeNewMonitorings(): Unit = {
|
private def initializeNewMonitorings(): Unit = {
|
||||||
LOG.debug(s"Looking for new monitorings created since $checkedOn")
|
debug(s"Looking for new monitorings created since $checkedOn")
|
||||||
val currentTime = ZonedDateTime.now()
|
val currentTime = ZonedDateTime.now()
|
||||||
val monitorings = dataService.getActiveMonitoringsSince(checkedOn)
|
val monitorings = dataService.getActiveMonitoringsSince(checkedOn)
|
||||||
LOG.debug(s"New active monitorings found: ${monitorings.length}")
|
debug(s"New active monitorings found: ${monitorings.length}")
|
||||||
checkedOn = currentTime
|
checkedOn = currentTime
|
||||||
initializeMonitorings(monitorings)
|
initializeMonitorings(monitorings)
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ class MonitoringService extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toDisable.foreach { case (id, monitoring) =>
|
toDisable.foreach { case (id, monitoring) =>
|
||||||
LOG.debug(s"Monitoring [#$id] is going to be disable as outdated")
|
debug(s"Monitoring [#$id] is going to be disable as outdated")
|
||||||
notifyChatAboutDisabledMonitoring(monitoring)
|
notifyChatAboutDisabledMonitoring(monitoring)
|
||||||
deactivateMonitoring(id)
|
deactivateMonitoring(id)
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ class MonitoringService extends Logger {
|
|||||||
bot.sendMessage(monitoring.source, lang(monitoring.userId).appointmentIsBooked(term, monitoring))
|
bot.sendMessage(monitoring.source, lang(monitoring.userId).appointmentIsBooked(term, monitoring))
|
||||||
deactivateMonitoring(monitoring.recordId)
|
deactivateMonitoring(monitoring.recordId)
|
||||||
case Left(ex) =>
|
case Left(ex) =>
|
||||||
LOG.error(s"Unable to book appointment by monitoring [${monitoring.recordId}]", ex)
|
error(s"Unable to book appointment by monitoring [${monitoring.recordId}]", ex)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -193,7 +193,7 @@ class MonitoringService extends Logger {
|
|||||||
def deactivateMonitoring(monitoringId: JLong): Unit = {
|
def deactivateMonitoring(monitoringId: JLong): Unit = {
|
||||||
activeMonitorings.remove(monitoringId).foreach {
|
activeMonitorings.remove(monitoringId).foreach {
|
||||||
case (monitoring, future) =>
|
case (monitoring, future) =>
|
||||||
LOG.debug(s"Deactivating monitoring [#$monitoringId]")
|
debug(s"Deactivating monitoring [#$monitoringId]")
|
||||||
if (!future.isCancelled) {
|
if (!future.isCancelled) {
|
||||||
future.cancel(true)
|
future.cancel(true)
|
||||||
monitoring.active = false
|
monitoring.active = false
|
||||||
@@ -230,12 +230,12 @@ class MonitoringService extends Logger {
|
|||||||
bot.sendMessage(monitoring.source, lang(monitoring.userId).termIsOutdated)
|
bot.sendMessage(monitoring.source, lang(monitoring.userId).termIsOutdated)
|
||||||
}
|
}
|
||||||
case Left(ex: InvalidLoginOrPasswordException) =>
|
case Left(ex: InvalidLoginOrPasswordException) =>
|
||||||
LOG.error(s"User entered invalid name or password. Monitoring will be disabled", ex)
|
error(s"User entered invalid name or password. Monitoring will be disabled", ex)
|
||||||
bot.sendMessage(monitoring.source, lang(monitoring.userId).loginHasChangedOrWrong)
|
bot.sendMessage(monitoring.source, lang(monitoring.userId).loginHasChangedOrWrong)
|
||||||
case Left(ex) => LOG.error(s"Error occurred during receiving terms for monitoring [#${monitoring.recordId}]", ex)
|
case Left(ex) => error(s"Error occurred during receiving terms for monitoring [#${monitoring.recordId}]", ex)
|
||||||
}
|
}
|
||||||
case None =>
|
case None =>
|
||||||
LOG.debug(s"Monitoring [#$monitoringId] not found in db")
|
debug(s"Monitoring [#$monitoringId] not found in db")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ class MonitoringService extends Logger {
|
|||||||
private def initialize(): Unit = {
|
private def initialize(): Unit = {
|
||||||
checkedOn = ZonedDateTime.now()
|
checkedOn = ZonedDateTime.now()
|
||||||
val monitorings = dataService.getActiveMonitorings
|
val monitorings = dataService.getActiveMonitorings
|
||||||
LOG.debug(s"Active monitorings found: ${monitorings.length}")
|
debug(s"Active monitorings found: ${monitorings.length}")
|
||||||
initializeMonitorings(monitorings)
|
initializeMonitorings(monitorings)
|
||||||
disableOutdated()
|
disableOutdated()
|
||||||
initializeDbChecker()
|
initializeDbChecker()
|
||||||
|
|||||||
@@ -24,15 +24,12 @@
|
|||||||
package com.lbs.server.service
|
package com.lbs.server.service
|
||||||
|
|
||||||
import com.lbs.api.json.model.LoginResponse
|
import com.lbs.api.json.model.LoginResponse
|
||||||
import com.lbs.common.ParametrizedLock
|
import com.lbs.common.{Logger, ParametrizedLock}
|
||||||
import com.lbs.server.exception.UserNotFoundException
|
import com.lbs.server.exception.UserNotFoundException
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
trait SessionSupport {
|
trait SessionSupport extends Logger {
|
||||||
|
|
||||||
private val Log = LoggerFactory.getLogger(classOf[SessionSupport])
|
|
||||||
|
|
||||||
case class Session(accessToken: String, tokenType: String)
|
case class Session(accessToken: String, tokenType: String)
|
||||||
|
|
||||||
@@ -74,11 +71,11 @@ trait SessionSupport {
|
|||||||
case Right(s) =>
|
case Right(s) =>
|
||||||
fn(s) match {
|
fn(s) match {
|
||||||
case Left(ex) if ex.getMessage.contains("session has expired") =>
|
case Left(ex) if ex.getMessage.contains("session has expired") =>
|
||||||
Log.debug(s"The session for account [#$accountId] has expired. Try to relogin")
|
debug(s"The session for account [#$accountId] has expired. Try to relogin")
|
||||||
sessions.remove(accountId)
|
sessions.remove(accountId)
|
||||||
session.flatMap(fn)
|
session.flatMap(fn)
|
||||||
case another =>
|
case another =>
|
||||||
Log.debug(s"Call to remote api function has completed with result:\n$another")
|
debug(s"Call to remote api function has completed with result:\n$another")
|
||||||
another
|
another
|
||||||
}
|
}
|
||||||
case Left(ex) => Left(ex)
|
case Left(ex) => Left(ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user