Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduler shedlock #68

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-batch'
testImplementation 'org.springframework.batch:spring-batch-test'

//scheduler
implementation 'net.javacrumbs.shedlock:shedlock-spring:4.14.0'
implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:4.14.0'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

@AllArgsConstructor
public enum Version {
MINIMUM("1.0.3"),
LATEST("1.0.3");
MINIMUM("1.0.4"),
LATEST("1.0.4");

@Getter
private final String version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;

import com.coniverse.dangjang.domain.notification.dto.fluentd.FcmMessage;
import com.coniverse.dangjang.domain.notification.service.NotificationSendService;
import com.coniverse.dangjang.domain.notification.service.NotificationService;
Expand All @@ -21,6 +24,7 @@
*/
@RequiredArgsConstructor
@Service
@EnableSchedulerLock(defaultLockAtMostFor = "PT10S")
public class SchedulerService {
private final NotificationService notificationService;
private final NotificationSendService notificationSendService;
Expand All @@ -34,6 +38,7 @@ public class SchedulerService {
* @since 1.1.0
*/
@Scheduled(cron = "0 0 18 * * *", zone = "Asia/Seoul")
@SchedulerLock(name = "SchedulerService_makeNotification", lockAtLeastFor = "PT60S", lockAtMostFor = "PT70S")
public void makeNotification() {
List<FcmMessage> fcmMessage = notificationService.makeAccessFcmMessage();
fcmMessage.forEach(message -> notificationSendService.sendMessage(message));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.coniverse.dangjang.global.config;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;

/**
* ๋ถ„์‚ฐ ์„œ๋ฒ„์—์„œ ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•จ
*
* @author EVE
* @since 1.1.0
*/

@Configuration
public class SchedulerConfiguration {
@Bean
public LockProvider lockProvider(DataSource dataSource) {
return new JdbcTemplateLockProvider((dataSource));
}

}
9 changes: 9 additions & 0 deletions src/main/resources/schema-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ DROP TABLE IF EXISTS PURCHASE_HISTORY;
DROP TABLE IF EXISTS POINT_PRODUCT;
DROP TABLE IF EXISTS USER_POINT;
DROP TABLE IF EXISTS USERS;
DROP TABLE IF EXISTS SHEDLOCK;

CREATE TABLE `USERS`
(
Expand Down Expand Up @@ -154,3 +155,11 @@ CREATE TABLE `NOTIFICATION`
FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) ON DELETE CASCADE,
FOREIGN KEY (`TYPE`) REFERENCES NOTIFICATION_TYPE (`TYPE`)
);

CREATE TABLE `SHEDLOCK` (
`NAME` VARCHAR(64),
`LOCK_UNTIL` TIMESTAMP(3) NULL,
`LOCKED_AT` TIMESTAMP(3) NULL,
`LOCKED_BY` VARCHAR(255),
PRIMARY KEY (NAME)
)
8 changes: 8 additions & 0 deletions src/test/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DROP TABLE IF EXISTS PURCHASE_HISTORY;
DROP TABLE IF EXISTS POINT_PRODUCT;
DROP TABLE IF EXISTS USER_POINT;
DROP TABLE IF EXISTS USERS;
DROP TABLE IF EXISTS SHEDLOCK;

CREATE TABLE `USERS`
(
Expand Down Expand Up @@ -156,3 +157,10 @@ CREATE TABLE `NOTIFICATION`
FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`),
FOREIGN KEY (`TYPE`) REFERENCES NOTIFICATION_TYPE (`TYPE`)
);
CREATE TABLE `SHEDLOCK` (
`NAME` VARCHAR(64),
`LOCK_UNTIL` TIMESTAMP(3) NULL,
`LOCKED_AT` TIMESTAMP(3) NULL,
`LOCKED_BY` VARCHAR(255),
PRIMARY KEY (NAME)
)
Loading