|
|
|
|
@ -27,6 +27,7 @@ class PinService(
|
|
|
|
|
private const val HTTP_STATUS_OK = 200
|
|
|
|
|
private const val POLLING_INTERVAL_MS = 1000L
|
|
|
|
|
private const val MS_TO_SECONDS = 1000f
|
|
|
|
|
private val TAG = PinService::class.java.simpleName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== 主执行方法 ====================
|
|
|
|
|
@ -64,7 +65,7 @@ class PinService(
|
|
|
|
|
taskConfig.notificationCache.add(notificationMessage)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogUtils.info("PinService: next list: ${nextList.map { "${it.regexp}, ${it.contain}" }}")
|
|
|
|
|
LogUtils.info("$TAG: next list: ${nextList.map { "${it.regexp}, ${it.contain}" }}")
|
|
|
|
|
|
|
|
|
|
withTimeoutOrNull(action.delay.toDuration(DurationUnit.SECONDS)) {
|
|
|
|
|
while (isActive) {
|
|
|
|
|
@ -73,20 +74,20 @@ class PinService(
|
|
|
|
|
if (shouldCheckForMessages(nextList, notificationCache)) {
|
|
|
|
|
val notificationMessages = haveNextCatchTargetMessage(notificationCache, nextList)
|
|
|
|
|
if (notificationMessages.isNotEmpty()) {
|
|
|
|
|
LogUtils.info("PinService: catch target message...")
|
|
|
|
|
LogUtils.info("$TAG: catch target message...")
|
|
|
|
|
messageLog.addAll(notificationMessages)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val elapsed = System.currentTimeMillis() - start
|
|
|
|
|
LogUtils.info("PinService: waiting for target message... delay: ${action.delay}s, elapsed: ${elapsed / MS_TO_SECONDS}s")
|
|
|
|
|
LogUtils.info("$TAG: waiting for target message... delay: ${action.delay}s, elapsed: ${elapsed / MS_TO_SECONDS}s")
|
|
|
|
|
delay(POLLING_INTERVAL_MS)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val cost = System.currentTimeMillis() - start
|
|
|
|
|
LogUtils.info("PinService: waiting finished, cost: ${cost / MS_TO_SECONDS}s")
|
|
|
|
|
LogUtils.info("$TAG: waiting finished, cost: ${cost / MS_TO_SECONDS}s")
|
|
|
|
|
NotificationManger.stopPolling()
|
|
|
|
|
return ExecutionResult(messageLog, cost, nextList)
|
|
|
|
|
}
|
|
|
|
|
@ -238,7 +239,7 @@ class PinService(
|
|
|
|
|
return emptyList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogUtils.info("PinService: message size: ${notificationCache.size}")
|
|
|
|
|
LogUtils.info("$TAG: message size: ${notificationCache.size}")
|
|
|
|
|
|
|
|
|
|
// 预编译正则表达式以提高性能
|
|
|
|
|
val compiledPatterns = compileRegexPatterns(nextList)
|
|
|
|
|
@ -264,12 +265,12 @@ class PinService(
|
|
|
|
|
compiledPatterns: Map<Next, Regex>
|
|
|
|
|
): NotificationMessage? {
|
|
|
|
|
for (notify in notificationCache) {
|
|
|
|
|
LogUtils.info("PinService: checking notify: ${notify.content}")
|
|
|
|
|
LogUtils.info("$TAG: checking notify: ${notify.content}")
|
|
|
|
|
|
|
|
|
|
for (next in nextList) {
|
|
|
|
|
if (next.step <= 0) continue
|
|
|
|
|
|
|
|
|
|
LogUtils.info("PinService: checking next: $next")
|
|
|
|
|
LogUtils.info("$TAG: checking next: $next")
|
|
|
|
|
|
|
|
|
|
if (matchesContain(notify, next) || matchesRegex(notify, next, compiledPatterns)) {
|
|
|
|
|
return notify
|
|
|
|
|
|