feat: ログを追加

This commit is contained in:
usbharu 2023-04-21 20:52:02 +09:00
parent a0fe4ffbd5
commit c9f86a16e7
3 changed files with 9 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import dev.usbharu.hideout.service.impl.UserService
import dev.usbharu.hideout.service.job.JobQueueParentService import dev.usbharu.hideout.service.job.JobQueueParentService
import io.ktor.client.* import io.ktor.client.*
import kjob.core.job.JobProps import kjob.core.job.JobProps
import org.slf4j.LoggerFactory
class ActivityPubNoteServiceImpl( class ActivityPubNoteServiceImpl(
private val httpClient: HttpClient, private val httpClient: HttpClient,
@ -17,6 +18,8 @@ class ActivityPubNoteServiceImpl(
private val userService: UserService private val userService: UserService
) : ActivityPubNoteService { ) : ActivityPubNoteService {
private val logger = LoggerFactory.getLogger(this::class.java)
override suspend fun createNote(post: PostEntity) { override suspend fun createNote(post: PostEntity) {
val followers = userService.findFollowersById(post.userId) val followers = userService.findFollowersById(post.userId)
val userEntity = userService.findById(post.userId) val userEntity = userService.findById(post.userId)
@ -35,6 +38,7 @@ class ActivityPubNoteServiceImpl(
val actor = props[DeliverPostJob.actor] val actor = props[DeliverPostJob.actor]
val note = Config.configData.objectMapper.readValue<Note>(props[DeliverPostJob.post]) val note = Config.configData.objectMapper.readValue<Note>(props[DeliverPostJob.post])
val inbox = props[DeliverPostJob.inbox] val inbox = props[DeliverPostJob.inbox]
logger.debug("createNoteJob: actor={}, note={}, inbox={}", actor, note, inbox)
httpClient.postAp( httpClient.postAp(
urlString = inbox, urlString = inbox,
username = "$actor#pubkey", username = "$actor#pubkey",

View File

@ -74,6 +74,7 @@ class ActivityPubServiceImpl(
} }
override suspend fun <T : HideoutJob> processActivity(job: JobContextWithProps<T>, hideoutJob: HideoutJob) { override suspend fun <T : HideoutJob> processActivity(job: JobContextWithProps<T>, hideoutJob: HideoutJob) {
logger.debug("processActivity: ${hideoutJob.name}")
when (hideoutJob) { when (hideoutJob) {
ReceiveFollowJob -> activityPubFollowService.receiveFollowJob(job.props as JobProps<ReceiveFollowJob>) ReceiveFollowJob -> activityPubFollowService.receiveFollowJob(job.props as JobProps<ReceiveFollowJob>)
DeliverPostJob -> activityPubNoteService.createNoteJob(job.props as JobProps<DeliverPostJob>) DeliverPostJob -> activityPubNoteService.createNoteJob(job.props as JobProps<DeliverPostJob>)

View File

@ -6,9 +6,12 @@ import kjob.core.KJob
import kjob.core.dsl.ScheduleContext import kjob.core.dsl.ScheduleContext
import kjob.core.kjob import kjob.core.kjob
import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.Database
import org.slf4j.LoggerFactory
class KJobJobQueueParentService(private val database: Database) : JobQueueParentService { class KJobJobQueueParentService(private val database: Database) : JobQueueParentService {
private val logger = LoggerFactory.getLogger(this::class.java)
val kjob: KJob = kjob(ExposedKJob) { val kjob: KJob = kjob(ExposedKJob) {
connectionDatabase = database connectionDatabase = database
isWorker = false isWorker = false
@ -19,6 +22,7 @@ class KJobJobQueueParentService(private val database: Database) : JobQueueParent
} }
override suspend fun <J : Job> schedule(job: J,block:ScheduleContext<J>.(J)->Unit) { override suspend fun <J : Job> schedule(job: J,block:ScheduleContext<J>.(J)->Unit) {
logger.debug("schedule job={}",job.name)
kjob.schedule(job,block) kjob.schedule(job,block)
} }
} }