Skip to content

Commit

Permalink
release: 1.5.3 (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Mar 3, 2025
2 parents afaa2c5 + 15b9aed commit 5876933
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package org.gitanimals.core.redis

import com.fasterxml.jackson.annotation.JsonIgnore
import org.gitanimals.core.IdGenerator
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
import org.slf4j.MDC
import org.springframework.context.ApplicationEvent

abstract class TransactionCommitRedisPubSubEvent(
val traceId: String = runCatching { MDC.get(TRACE_ID) }.getOrElse {
IdGenerator.generate().toString()
},
val traceId: String,
@JsonIgnore
val channel: String,
source: Any,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.gitanimals.guild.domain.event

import org.gitanimals.core.DomainEventPublisher
import org.gitanimals.core.IdGenerator
import org.gitanimals.core.filter.MDCFilter
import org.gitanimals.core.redis.RedisPubSubChannel
import org.gitanimals.core.redis.TransactionCommitRedisPubSubEvent
import org.gitanimals.core.DomainEventPublisher
import org.slf4j.MDC

data class GuildContributionUpdated(
val guildId: Long,
Expand All @@ -11,6 +14,9 @@ data class GuildContributionUpdated(
val contributions: Long,
val updatedContributions: Long,
) : TransactionCommitRedisPubSubEvent(
traceId = runCatching { MDC.get(MDCFilter.TRACE_ID) }.getOrElse {
IdGenerator.generate().toString()
},
channel = RedisPubSubChannel.GUILD_CONTRIBUTION_UPDATED,
source = DomainEventPublisher::class,
)
6 changes: 4 additions & 2 deletions src/main/kotlin/org/gitanimals/render/app/AnimationFacade.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.gitanimals.render.app

import org.gitanimals.core.Mode
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
import org.gitanimals.render.domain.User
import org.gitanimals.render.domain.UserService
import org.gitanimals.render.domain.event.NewUserCreated
import org.gitanimals.render.domain.event.Visited
import org.rooftop.netx.api.SagaManager
import org.slf4j.MDC
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import org.springframework.web.client.RestClientException
Expand All @@ -22,7 +24,7 @@ class AnimationFacade(
return when (userService.existsByName(username)) {
true -> {
val svgAnimation = userService.getFarmAnimationByUsername(username)
eventPublisher.publishEvent(Visited(username))
eventPublisher.publishEvent(Visited(username, MDC.get(TRACE_ID)))
svgAnimation
}

Expand All @@ -38,7 +40,7 @@ class AnimationFacade(
return when (userService.existsByName(username)) {
true -> {
val svgAnimation = userService.getLineAnimationByUsername(username, personaId, mode)
eventPublisher.publishEvent(Visited(username))
eventPublisher.publishEvent(Visited(username, MDC.get(TRACE_ID)))
svgAnimation
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.gitanimals.render.domain.event

import org.gitanimals.core.DomainEventPublisher
import org.gitanimals.core.IdGenerator
import org.gitanimals.core.filter.MDCFilter
import org.gitanimals.core.instant
import org.gitanimals.core.redis.RedisPubSubChannel
import org.gitanimals.core.redis.TransactionCommitRedisPubSubEvent
import org.slf4j.MDC
import java.time.Instant

data class UserContributionUpdated(
Expand All @@ -13,6 +16,9 @@ data class UserContributionUpdated(
val userContributionUpdated: Boolean = true,
val contributionUpdatedAt: Instant = instant(),
) : TransactionCommitRedisPubSubEvent(
traceId = runCatching { MDC.get(MDCFilter.TRACE_ID) }.getOrElse {
IdGenerator.generate().toString()
},
channel = RedisPubSubChannel.USER_CONTRIBUTION_UPDATED,
source = DomainEventPublisher::class,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.gitanimals.render.domain.event

data class Visited(
val username: String
val username: String,
val traceId: String,
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.gitanimals.render.infra

import org.gitanimals.core.IdGenerator
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
import org.gitanimals.render.app.ContributionApi
import org.gitanimals.render.app.IdentityApi
import org.gitanimals.render.domain.UserService
import org.gitanimals.render.domain.event.Visited
import org.rooftop.netx.api.*
import org.rooftop.netx.meta.SagaHandler
import org.slf4j.LoggerFactory
import org.slf4j.MDC
import org.springframework.context.event.EventListener
import org.springframework.scheduling.annotation.Async
import java.time.ZoneId
Expand All @@ -26,6 +28,7 @@ class VisitedEventListener(
@EventListener(Visited::class)
fun increaseUserVisited(visited: Visited) {
runCatching {
MDC.put(TRACE_ID, visited.traceId)
val username = visited.username
userService.increaseVisit(username)

Expand All @@ -49,6 +52,8 @@ class VisitedEventListener(
logger.info("Increase point to user. username: \"$username\", point:\"${increaseContributionCount * 100}\"")
}.onFailure {
logger.error("Cannot increase visit or point to user. username: \"${visited.username}\"", it)
}.also {
MDC.remove(TRACE_ID)
}
}
}

0 comments on commit 5876933

Please sign in to comment.