일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- php
- redis
- linux
- laravel
- ubuntu
- Web Server
- 요리
- java
- IntelliJ
- Oracle
- AWS
- ReactJS
- MySQL
- Git
- tool
- springboot
- Spring Boot
- JVM
- jsp
- Gradle
- javascript
- Design Patterns
- it
- jenkins
- Spring
- db
- elasticsearch
- Spring Batch
- 맛집
- devops
Archives
- Today
- Total
아무거나
스케쥴러 구현 (@EnableScheduling) 본문
반응형
참고소스: https://github.com/bkjeon1614/kotlin-example-code/tree/main/kotlin-jpa-codebase
- Application.kt 에 설정
... import org.springframework.scheduling.annotation.EnableScheduling @EnableScheduling // 추가 class TestApplication { ... fun main(...) }
- AppHealthCheckScheduler.kt 스케쥴러 테스트용 코드 작성
package com.bkjeon.base.v1.schedule import org.apache.http.client.methods.HttpGet import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Value import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Component @Component class AppHealthCheckScheduler { @Value("\${spring.config.activate.on-profile:}") lateinit var env: String companion object { private val logger = LoggerFactory.getLogger(AppHealthCheckScheduler::class.java) private val httpClient: CloseableHttpClient = HttpClients.createDefault() } // 10 분에 1번 @Scheduled(cron = "* 0/10 * * * *") fun isAppHealthCheck() { val httpGet = HttpGet("https://www.naver.com/") try { logger.info(">>>>>>>>>>>>>>>>>>>> Health Check: $env") httpClient.execute(httpGet) } catch (e: Exception) { logger.error(">>>>>>>>>>>>>>>>>>>> Error: $e, Env: $env") } } }
반응형
'Java & Kotlin > Kotlin' 카테고리의 다른 글
객체 간 매핑을 위한 Kotlin MapStruct 적용 (1) | 2024.06.28 |
---|---|
Kotlin + Spring Boot DynamoDB SDK 적용 (0) | 2024.05.30 |
Kotlin + Spring Boot 에 Ehcache 적용 (0) | 2024.05.30 |
Comments