-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fae691f
commit 13eab71
Showing
18 changed files
with
207 additions
and
14 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../alignlab/batch/job/PoseCountUpdateJob.kt → ...batch/posecount/job/PoseCountUpdateJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...lab/batch/scheduler/PoseCountScheduler.kt → ...posecount/scheduler/PoseCountScheduler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/kotlin/com/hero/alignlab/batch/statistics/job/HeroStatisticsJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.hero.alignlab.batch.statistics.job | ||
|
||
import com.hero.alignlab.client.discord.DiscordWebhookService | ||
import com.hero.alignlab.client.discord.model.request.SendMessageRequest | ||
import com.hero.alignlab.domain.discussion.infrastructure.DiscussionRepository | ||
import com.hero.alignlab.domain.group.infrastructure.GroupRepository | ||
import com.hero.alignlab.domain.group.infrastructure.GroupUserRepository | ||
import com.hero.alignlab.domain.log.infrastructure.SystemActionLogRepository | ||
import com.hero.alignlab.domain.notification.infrastructure.PoseNotificationRepository | ||
import com.hero.alignlab.domain.pose.infrastructure.PoseSnapshotRepository | ||
import com.hero.alignlab.domain.user.infrastructure.CredentialUserInfoRepository | ||
import com.hero.alignlab.domain.user.infrastructure.OAuthUserInfoRepository | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.coroutineScope | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Component | ||
class HeroStatisticsJob( | ||
private val discordWebhookService: DiscordWebhookService, | ||
|
||
/** repository */ | ||
private val groupRepository: GroupRepository, | ||
private val groupUserRepository: GroupUserRepository, | ||
private val discussionRepository: DiscussionRepository, | ||
private val imageRepository: GroupRepository, | ||
private val systemActionLogRepository: SystemActionLogRepository, | ||
private val poseNotificationRepository: PoseNotificationRepository, | ||
private val poseSnapshotRepository: PoseSnapshotRepository, | ||
private val credentialUserInfoRepository: CredentialUserInfoRepository, | ||
private val oAuthUserInfoRepository: OAuthUserInfoRepository, | ||
private val userInfoRepository: CredentialUserInfoRepository, | ||
) { | ||
suspend fun sendHeroStatistics(title: String, fromDate: LocalDateTime, toDate: LocalDateTime) { | ||
coroutineScope { | ||
val groupCount = async(Dispatchers.IO) { | ||
groupRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val groupUserCount = async(Dispatchers.IO) { | ||
groupUserRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val discussionCount = async(Dispatchers.IO) { | ||
discussionRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val syslogCount = async(Dispatchers.IO) { | ||
systemActionLogRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val poseNotificationCount = async(Dispatchers.IO) { | ||
poseNotificationRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val poseSnapshotCount = async(Dispatchers.IO) { | ||
poseSnapshotRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val credentialUserInfoCount = async(Dispatchers.IO) { | ||
credentialUserInfoRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val oAuthUserInfoCount = async(Dispatchers.IO) { | ||
oAuthUserInfoRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val userInfoCount = async(Dispatchers.IO) { | ||
userInfoRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
val imageCount = async(Dispatchers.IO) { | ||
imageRepository.countByCreatedAtBetween(fromDate, toDate) | ||
}.await() | ||
|
||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") | ||
|
||
val message = """ | ||
$title | ||
- targetDate: ${fromDate.format(formatter)} ~ ${toDate.format(formatter)} | ||
- 그룹 생성수 : $groupCount | ||
- 그룹 유저 생성수 : $groupUserCount | ||
- 문의하기 생성수 : $discussionCount | ||
- api 호출량 : $syslogCount | ||
- 포즈 알림 설정수 : $poseNotificationCount | ||
- 포즈 스냅샷 생성수 : $poseSnapshotCount | ||
- 일반 회원가입수 : $credentialUserInfoCount | ||
- OAuth 회원가입수 : $oAuthUserInfoCount | ||
- 유저 생성수 : $userInfoCount | ||
- 이미지 생성수 : $imageCount | ||
""".trimIndent() | ||
|
||
discordWebhookService.sendMessage(SendMessageRequest(message)) | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/hero/alignlab/batch/statistics/scheduler/HeroStatisticsScheduler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.hero.alignlab.batch.statistics.scheduler | ||
|
||
import com.hero.alignlab.batch.statistics.job.HeroStatisticsJob | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDateTime | ||
|
||
@Component | ||
class HeroStatisticsScheduler( | ||
private val heroStatisticsJob: HeroStatisticsJob | ||
) { | ||
@Scheduled(cron = "0 0 0/1 * * *") | ||
fun dailyRunJob() { | ||
CoroutineScope(Dispatchers.IO + Job()).launch { | ||
val toDate = LocalDateTime.now() | ||
val fromDate = LocalDateTime.now().minusHours(1) | ||
|
||
heroStatisticsJob.sendHeroStatistics( | ||
title = "극락통계 1시간 단위 [$fromDate ~ $toDate]", | ||
fromDate = fromDate, | ||
toDate = toDate | ||
) | ||
} | ||
} | ||
|
||
@Scheduled(cron = "0 0 9 * * *") | ||
fun runDailySummary() { | ||
CoroutineScope(Dispatchers.IO + Job()).launch { | ||
val toDate = LocalDateTime.now() | ||
val fromDate = LocalDateTime.now().minusDays(1) | ||
|
||
heroStatisticsJob.sendHeroStatistics( | ||
title = "극락통계 1일 단위 [$fromDate ~ $toDate]", | ||
fromDate = fromDate, | ||
toDate = toDate | ||
) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/hero/alignlab/client/discord/DiscordWebhookService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.hero.alignlab.client.discord | ||
|
||
import com.hero.alignlab.client.discord.client.DiscordWebhookClient | ||
import com.hero.alignlab.client.discord.model.request.SendMessageRequest | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class DiscordWebhookService( | ||
private val discordWebhookClient: DiscordWebhookClient, | ||
) { | ||
suspend fun sendMessage(request: SendMessageRequest) { | ||
withContext(Dispatchers.IO) { | ||
discordWebhookClient.sendMessage(request) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters