Skip to content

Commit

Permalink
✨ feat: 스케줄러 기본 설정 & 지역 DB 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
seheonnn authored May 26, 2024
2 parents f72c806 + f960634 commit 061edf9
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 2 deletions.
2 changes: 2 additions & 0 deletions weather-service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*-secret.yml
*.Ds_Store
**/data/mysql/

HELP.md
.gradle
Expand Down
5 changes: 4 additions & 1 deletion weather-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ ext {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"

testImplementation 'org.springframework.boot:spring-boot-starter-test'
// DB
runtimeOnly 'com.mysql:mysql-connector-j'

//Webflux
implementation 'org.springframework.boot:spring-boot-starter-webflux'
Expand Down
11 changes: 11 additions & 0 deletions weather-service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
version: '3'

services:
mysql:
image: mysql:latest
container_name: waither
environment:
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: root1234!
MYSQL_DATABASE: waither
ports:
- "3306:3306"
volumes:
- ./data/mysql:/var/lib/mysql
redis:
image: redis:latest
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
@EnableRedisRepositories
public class WeatherServiceApplication {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.waither.weatherservice.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@Entity
@Table(name = "region")
public class Region {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String stnID;
private String stnKo;
private String stnSp;
private double longitude;
private double latitude;
private String fctId;
private String wrnId;
private String wrnKo;
private String sfcStn;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.waither.weatherservice.scheduler;

import java.net.URISyntaxException;
import java.time.LocalDateTime;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.scheduling.annotation.Scheduled;

import com.waither.weatherservice.service.WeatherService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
@ConfigurationProperties
public class SchedulerConfig {

private final WeatherService weatherService;
@Scheduled(cron = "0 0 14,17,20 * * *")
public void createDailyWeather() throws URISyntaxException {

LocalDateTime now = LocalDateTime.now();
String[] dateTime = weatherService.convertLocalDateTimeToString(now).split("_");
// TODO 지역 DB 정리 후 변경 예정
weatherService.createDailyWeather(55, 127, dateTime[0], dateTime[1]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void createExpectedWeather(
public void createDailyWeather(int nx,
int ny,
String baseDate,
String baseTime) throws URISyntaxException, JsonProcessingException {
String baseTime) throws URISyntaxException {

// Base_time : 0200, 0500, 0800, 1100, 1400, 1700, 2000, 2300 업데이트 (1일 8회)
List<ForeCastOpenApiResponse.Item> items = openApiUtil.callForeCastApi(nx, ny, baseDate, baseTime, 350,
Expand Down
Binary file modified weather-service/src/main/resources/api/Region.xlsx
Binary file not shown.

0 comments on commit 061edf9

Please sign in to comment.