-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #371 from daedongbread/345-feature-opensearch-도입-및…
…-데이터-처리-프로그램-구현 feat: Divide profiles of schedulers for test
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/depromeet/breadmapbackend/domain/search/OpenSearchLoadTestScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.depromeet.breadmapbackend.domain.search; | ||
|
||
import com.depromeet.breadmapbackend.domain.search.dto.OpenSearchIndex; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.redisson.Redisson; | ||
import org.redisson.api.RLock; | ||
import org.redisson.api.RedissonClient; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Slf4j | ||
@Component | ||
@Profile("!prod") | ||
@RequiredArgsConstructor | ||
public class OpenSearchLoadTestScheduler { | ||
|
||
private final OpenSearchService openSearchService; | ||
@Scheduled(cron = "0 0 0/6 * * *") // for local test | ||
public void loadEntireData() throws IOException { | ||
RedissonClient client = Redisson.create(); | ||
|
||
RLock lock = client.getLock("Load-Entire-Data"); | ||
try { | ||
|
||
if (lock.tryLock(2, TimeUnit.HOURS)) { | ||
log.info("========================= Loading entire data to search engine ========================="); | ||
|
||
openSearchService.deleteAndCreateIndex(OpenSearchIndex.BAKERY_SEARCH.getIndexNameWithVersion()); | ||
openSearchService.deleteAndCreateIndex(OpenSearchIndex.BREAD_SEARCH.getIndexNameWithVersion()); | ||
|
||
openSearchService.loadEntireData(); | ||
log.info("Job loadEntireData executed by this instance"); | ||
} else { | ||
log.info("Job loadEntireData skipped by this instance"); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
} finally { | ||
lock.unlock(); | ||
} | ||
|
||
} | ||
} |