From 2a52dd26278549ad46badc07ae08519371f4bb08 Mon Sep 17 00:00:00 2001 From: aesperer Date: Sat, 7 Oct 2023 13:24:40 +0900 Subject: [PATCH 1/5] create :: batch application, base job parameters --- bitgouel-batch/build.gradle.kts | 8 +++++--- .../src/main/kotlin/team/msg/BatchApplication.kt | 14 ++++++++++++++ .../kotlin/team/msg/common/BaseJobParameter.kt | 8 ++++++++ bitgouel-batch/src/main/resources/application.yml | 7 +++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 bitgouel-batch/src/main/kotlin/team/msg/BatchApplication.kt create mode 100644 bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt create mode 100644 bitgouel-batch/src/main/resources/application.yml diff --git a/bitgouel-batch/build.gradle.kts b/bitgouel-batch/build.gradle.kts index bf015e139..9d35e47cd 100644 --- a/bitgouel-batch/build.gradle.kts +++ b/bitgouel-batch/build.gradle.kts @@ -1,8 +1,10 @@ +import org.springframework.boot.gradle.tasks.bundling.BootJar +val jar: Jar by tasks +val bootJar: BootJar by tasks -plugins { - -} +jar.enabled = true +bootJar.enabled = true dependencies { implementation(project(":bitgouel-domain")) diff --git a/bitgouel-batch/src/main/kotlin/team/msg/BatchApplication.kt b/bitgouel-batch/src/main/kotlin/team/msg/BatchApplication.kt new file mode 100644 index 000000000..e303b1891 --- /dev/null +++ b/bitgouel-batch/src/main/kotlin/team/msg/BatchApplication.kt @@ -0,0 +1,14 @@ +package team.msg + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication +import kotlin.system.exitProcess + +@SpringBootApplication +class BatchApplication + +fun main(args: Array) { + val applicationContext = runApplication(*args) + exitProcess(SpringApplication.exit(applicationContext)) // 배치 완료 후 바로 process 종료 +} diff --git a/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt b/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt new file mode 100644 index 000000000..d7c2cc7de --- /dev/null +++ b/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt @@ -0,0 +1,8 @@ +package team.msg.common + +/** + * 개발/QA 도중에 같은 Job 파라미터 값으로 배치 실행이 가능하도록 해줍니다. + * version은 1부터 시작합니다. + */ +open class BaseJobParameter(val version: Int) { +} \ No newline at end of file diff --git a/bitgouel-batch/src/main/resources/application.yml b/bitgouel-batch/src/main/resources/application.yml new file mode 100644 index 000000000..c364b07ab --- /dev/null +++ b/bitgouel-batch/src/main/resources/application.yml @@ -0,0 +1,7 @@ +spring: + datasource: + hikari: + jdbc-url: jdbc:mysql://${DB_URL:localhost:3306}/${DB_NAME:bitgouel}?useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Seoul&allowPublicKeyRetrieval=true + username: ${DB_USER:bitgouel-admin} + password: ${DB_PASSWORD:Esperer123!} + driver-class-name: com.mysql.cj.jdbc.Driver \ No newline at end of file From 114e52ef539ec55498bd148115f5f41f42b3a4d9 Mon Sep 17 00:00:00 2001 From: aesperer Date: Sat, 7 Oct 2023 18:03:26 +0900 Subject: [PATCH 2/5] create :: schema MySQL batch table --- bitgouel-batch/src/main/resources/schema.sql | 101 +++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 bitgouel-batch/src/main/resources/schema.sql diff --git a/bitgouel-batch/src/main/resources/schema.sql b/bitgouel-batch/src/main/resources/schema.sql new file mode 100644 index 000000000..3378a9a75 --- /dev/null +++ b/bitgouel-batch/src/main/resources/schema.sql @@ -0,0 +1,101 @@ +-- Autogenerated: do not edit this file + +CREATE TABLE BATCH_JOB_INSTANCE ( + JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY , + VERSION BIGINT , + JOB_NAME VARCHAR(100) NOT NULL, + JOB_KEY VARCHAR(32) NOT NULL, + constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY) +) ENGINE=InnoDB; + +CREATE TABLE BATCH_JOB_EXECUTION ( + JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , + VERSION BIGINT , + JOB_INSTANCE_ID BIGINT NOT NULL, + CREATE_TIME DATETIME(6) NOT NULL, + START_TIME DATETIME(6) DEFAULT NULL , + END_TIME DATETIME(6) DEFAULT NULL , + STATUS VARCHAR(10) , + EXIT_CODE VARCHAR(2500) , + EXIT_MESSAGE VARCHAR(2500) , + LAST_UPDATED DATETIME(6), + JOB_CONFIGURATION_LOCATION VARCHAR(2500) NULL, + constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) +) ENGINE=InnoDB; + +CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( + JOB_EXECUTION_ID BIGINT NOT NULL , + TYPE_CD VARCHAR(6) NOT NULL , + KEY_NAME VARCHAR(100) NOT NULL , + STRING_VAL VARCHAR(250) , + DATE_VAL DATETIME(6) DEFAULT NULL , + LONG_VAL BIGINT , + DOUBLE_VAL DOUBLE PRECISION , + IDENTIFYING CHAR(1) NOT NULL , + constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) +) ENGINE=InnoDB; + +CREATE TABLE BATCH_STEP_EXECUTION ( + STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , + VERSION BIGINT NOT NULL, + STEP_NAME VARCHAR(100) NOT NULL, + JOB_EXECUTION_ID BIGINT NOT NULL, + START_TIME DATETIME(6) NOT NULL , + END_TIME DATETIME(6) DEFAULT NULL , + STATUS VARCHAR(10) , + COMMIT_COUNT BIGINT , + READ_COUNT BIGINT , + FILTER_COUNT BIGINT , + WRITE_COUNT BIGINT , + READ_SKIP_COUNT BIGINT , + WRITE_SKIP_COUNT BIGINT , + PROCESS_SKIP_COUNT BIGINT , + ROLLBACK_COUNT BIGINT , + EXIT_CODE VARCHAR(2500) , + EXIT_MESSAGE VARCHAR(2500) , + LAST_UPDATED DATETIME(6), + constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) +) ENGINE=InnoDB; + +CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( + STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, + SHORT_CONTEXT VARCHAR(2500) NOT NULL, + SERIALIZED_CONTEXT TEXT , + constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) +) ENGINE=InnoDB; + +CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( + JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, + SHORT_CONTEXT VARCHAR(2500) NOT NULL, + SERIALIZED_CONTEXT TEXT , + constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) +) ENGINE=InnoDB; + +CREATE TABLE BATCH_STEP_EXECUTION_SEQ ( + ID BIGINT NOT NULL, + UNIQUE_KEY CHAR(1) NOT NULL, + constraint UNIQUE_KEY_UN unique (UNIQUE_KEY) +) ENGINE=InnoDB; + +INSERT INTO BATCH_STEP_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_STEP_EXECUTION_SEQ); + +CREATE TABLE BATCH_JOB_EXECUTION_SEQ ( + ID BIGINT NOT NULL, + UNIQUE_KEY CHAR(1) NOT NULL, + constraint UNIQUE_KEY_UN unique (UNIQUE_KEY) +) ENGINE=InnoDB; + +INSERT INTO BATCH_JOB_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_EXECUTION_SEQ); + +CREATE TABLE BATCH_JOB_SEQ ( + ID BIGINT NOT NULL, + UNIQUE_KEY CHAR(1) NOT NULL, + constraint UNIQUE_KEY_UN unique (UNIQUE_KEY) +) ENGINE=InnoDB; + +INSERT INTO BATCH_JOB_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_SEQ); From 05d6d4e4450bdd7ab78ea7b7ba6cedefabb10228 Mon Sep 17 00:00:00 2001 From: aesperer Date: Sat, 7 Oct 2023 19:02:27 +0900 Subject: [PATCH 3/5] add :: batch job enabled false --- .../src/main/kotlin/team/msg/BatchApplication.kt | 2 ++ bitgouel-batch/src/main/resources/application.yml | 6 +++++- .../src/main/kotlin/common/LoggerDelegator.kt | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 bitgouel-domain/src/main/kotlin/common/LoggerDelegator.kt diff --git a/bitgouel-batch/src/main/kotlin/team/msg/BatchApplication.kt b/bitgouel-batch/src/main/kotlin/team/msg/BatchApplication.kt index e303b1891..cceb79918 100644 --- a/bitgouel-batch/src/main/kotlin/team/msg/BatchApplication.kt +++ b/bitgouel-batch/src/main/kotlin/team/msg/BatchApplication.kt @@ -1,11 +1,13 @@ package team.msg +import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import kotlin.system.exitProcess @SpringBootApplication +@EnableBatchProcessing class BatchApplication fun main(args: Array) { diff --git a/bitgouel-batch/src/main/resources/application.yml b/bitgouel-batch/src/main/resources/application.yml index c364b07ab..0ecb73a99 100644 --- a/bitgouel-batch/src/main/resources/application.yml +++ b/bitgouel-batch/src/main/resources/application.yml @@ -4,4 +4,8 @@ spring: jdbc-url: jdbc:mysql://${DB_URL:localhost:3306}/${DB_NAME:bitgouel}?useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Seoul&allowPublicKeyRetrieval=true username: ${DB_USER:bitgouel-admin} password: ${DB_PASSWORD:Esperer123!} - driver-class-name: com.mysql.cj.jdbc.Driver \ No newline at end of file + driver-class-name: com.mysql.cj.jdbc.Driver + + batch: + job: + enabled: false \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/common/LoggerDelegator.kt b/bitgouel-domain/src/main/kotlin/common/LoggerDelegator.kt new file mode 100644 index 000000000..bbe0250d0 --- /dev/null +++ b/bitgouel-domain/src/main/kotlin/common/LoggerDelegator.kt @@ -0,0 +1,9 @@ +package common + +import org.slf4j.LoggerFactory +import java.util.logging.Logger + +class LoggerDelegator { + private var logger: Logger? = null + operator fun getValue(thisRef: Any?, property: Any?) = logger ?: LoggerFactory.getLogger(thisRef?.javaClass)!! +} \ No newline at end of file From 30dc3aa91eeda95b98345c1a61ef5032865768b4 Mon Sep 17 00:00:00 2001 From: aesperer Date: Sat, 7 Oct 2023 19:02:59 +0900 Subject: [PATCH 4/5] =?UTF-8?q?chore=20::=20base=20job=20parameter?= =?UTF-8?q?=EC=9D=98=20=EC=A3=BC=EC=84=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/team/msg/common/BaseJobParameter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt b/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt index d7c2cc7de..9e22a3c07 100644 --- a/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt +++ b/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt @@ -1,7 +1,7 @@ package team.msg.common /** - * 개발/QA 도중에 같은 Job 파라미터 값으로 배치 실행이 가능하도록 해줍니다. + * 개발/QA 도중에 같은 Job 파라미터 값으로 배치 실행이 가능하도록 version을 지정합니다. * version은 1부터 시작합니다. */ open class BaseJobParameter(val version: Int) { From 7f3f66d43320ec79139a4c5abb8d4d36a8c6b393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=9D=AC=EB=A7=9D?= <105429536+esperar@users.noreply.github.com> Date: Sat, 7 Oct 2023 19:47:56 +0900 Subject: [PATCH 5/5] Update bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 노현주 <106813267+ani2689@users.noreply.github.com> --- .../src/main/kotlin/team/msg/common/BaseJobParameter.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt b/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt index 9e22a3c07..c25166b3e 100644 --- a/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt +++ b/bitgouel-batch/src/main/kotlin/team/msg/common/BaseJobParameter.kt @@ -4,5 +4,4 @@ package team.msg.common * 개발/QA 도중에 같은 Job 파라미터 값으로 배치 실행이 가능하도록 version을 지정합니다. * version은 1부터 시작합니다. */ -open class BaseJobParameter(val version: Int) { -} \ No newline at end of file +open class BaseJobParameter(val version: Int) \ No newline at end of file