mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-09 22:01:13 +00:00
Compare commits
4 Commits
b1432c662f
...
debug
Author | SHA1 | Date | |
---|---|---|---|
|
f27c0da775 | ||
|
c528448b5e | ||
|
db78bf3ff6 | ||
|
d7d4228063 |
@@ -28,6 +28,7 @@ import java.lang.Thread
|
||||
import java.net.SocketTimeoutException
|
||||
import java.nio.charset.Charset
|
||||
import java.time.LocalDateTime
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
object ChzzkHandler {
|
||||
private val handlers = mutableListOf<UserHandler>()
|
||||
@@ -36,6 +37,9 @@ object ChzzkHandler {
|
||||
@Volatile private var running: Boolean = false
|
||||
private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
||||
|
||||
private val lastRunMap = ConcurrentHashMap<String, Long>()
|
||||
private val requiredWait = 300_000L
|
||||
|
||||
fun addUser(chzzkChannel: ChzzkChannel, user: User) {
|
||||
handlers.add(UserHandler(chzzkChannel, logger, user, streamStartTime = LocalDateTime.now()))
|
||||
}
|
||||
@@ -128,6 +132,7 @@ object ChzzkHandler {
|
||||
} catch (e: Exception) {
|
||||
logger.info("Thread 1 Exception: ${it.channel.channelName} / ${e.stackTraceToString()}")
|
||||
} finally {
|
||||
lastRunMap[it.channel.channelId] = System.currentTimeMillis()
|
||||
Thread.sleep(5000)
|
||||
}
|
||||
}
|
||||
@@ -136,12 +141,21 @@ object ChzzkHandler {
|
||||
}
|
||||
|
||||
val threadRunner2 = Runnable {
|
||||
logger.info("Thread 2 started!")
|
||||
logger.info("Thread 2 started!")
|
||||
while (running) {
|
||||
handlers.forEach {
|
||||
if (!running) return@forEach
|
||||
try {
|
||||
val now = System.currentTimeMillis()
|
||||
val lastRun = lastRunMap[it.channel.channelId] ?: 0L
|
||||
val waitedTime = now - lastRun
|
||||
|
||||
if(waitedTime < requiredWait) {
|
||||
val sleepTime = requiredWait - waitedTime
|
||||
logger.info("Thread 2 Sleep: ${it.channel.channelName} / ${sleepTime}ms")
|
||||
Thread.sleep(sleepTime)
|
||||
}
|
||||
|
||||
val streamInfo = Connector.getLive(it.channel.channelId)
|
||||
if (streamInfo?.isOnline == true && !it.isActive) {
|
||||
try {
|
||||
|
@@ -14,7 +14,7 @@ object Metrics {
|
||||
.register(registry)
|
||||
|
||||
var activeStreamer = 0.0
|
||||
val activateGauge: Gauge = Gauge.builder("active_streamer_gauge", this) { streamer }
|
||||
val activateGauge: Gauge = Gauge.builder("active_streamer_gauge", this) { activeStreamer }
|
||||
.description("Current Active Streamer Count")
|
||||
.register(registry)
|
||||
|
||||
@@ -24,8 +24,10 @@ object Metrics {
|
||||
.register(registry)
|
||||
|
||||
fun refreshStreamerMetrics() {
|
||||
streamer = UserService.getAllUsers().size.toDouble()
|
||||
activeStreamer = UserService.getAllUsers().filter { !it.isDisabled }.size.toDouble()
|
||||
val streamers = UserService.getAllUsers()
|
||||
|
||||
streamer = streamers.size.toDouble()
|
||||
activeStreamer = streamers.filter { !it.isDisabled }.size.toDouble()
|
||||
}
|
||||
|
||||
fun increaseStreaming(inc: Int = 1) {
|
||||
@@ -34,4 +36,8 @@ object Metrics {
|
||||
fun decreaseStreaming(dec: Int = 1) {
|
||||
streaming -= dec
|
||||
}
|
||||
|
||||
init {
|
||||
refreshStreamerMetrics()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user