diff --git a/src/main/kotlin/com/yapp/web2/batch/job/JobCompletionListener.kt b/src/main/kotlin/com/yapp/web2/batch/job/JobCompletionListener.kt index 17c9728..4d4b6e7 100644 --- a/src/main/kotlin/com/yapp/web2/batch/job/JobCompletionListener.kt +++ b/src/main/kotlin/com/yapp/web2/batch/job/JobCompletionListener.kt @@ -1,6 +1,6 @@ package com.yapp.web2.batch.job -import com.yapp.web2.infra.slack.SlackServiceImpl +import com.yapp.web2.infra.slack.SlackService import org.slf4j.LoggerFactory import org.springframework.batch.core.BatchStatus import org.springframework.batch.core.JobExecution @@ -9,20 +9,27 @@ import org.springframework.stereotype.Component import java.util.stream.Collectors @Component -class JobCompletionListener : JobExecutionListenerSupport() { +class JobCompletionListener( + private val slackApi: SlackService +) : JobExecutionListenerSupport() { private val log = LoggerFactory.getLogger(javaClass) - private val slackApi: SlackServiceImpl = SlackServiceImpl() override fun afterJob(jobExecution: JobExecution) { val jobStatus = jobExecution.status log.info("Job {} - {}", jobStatus, jobExecution.jobInstance.jobName) + if (jobStatus == BatchStatus.COMPLETED) { + slackApi.sendSlackAlarm( + "*`${jobExecution.jobInstance.jobName}`* - executed" + ) + } + if (jobStatus != BatchStatus.COMPLETED) { val errorMessage = String.format( "*`Batch Error`* - %s", getErrorMessage(jobExecution).replace("\"", "") ) - slackApi.sendMessage(errorMessage) + slackApi.sendSlackAlarm(errorMessage) } }