-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5575b05
commit 69a124a
Showing
6 changed files
with
74 additions
and
11 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
50 changes: 50 additions & 0 deletions
50
.../org/cardanofoundation/ledgersync/explorerconsumer/listeners/LedgerSyncEventListener.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,50 @@ | ||
package org.cardanofoundation.ledgersync.explorerconsumer.listeners; | ||
|
||
import com.bloxbean.cardano.yaci.store.core.domain.Cursor; | ||
import com.bloxbean.cardano.yaci.store.core.service.CursorService; | ||
import com.bloxbean.cardano.yaci.store.core.service.StartService; | ||
import com.bloxbean.cardano.yaci.store.core.storage.api.CursorStorage; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.cardanofoundation.ledgersync.explorerconsumer.repository.BlockRepository; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class LedgerSyncEventListener { | ||
private final StartService startService; | ||
private final CursorService cursorService; | ||
private final CursorStorage cursorStorage; | ||
private final BlockRepository blockRepository; | ||
|
||
@Value("${store.sync-auto-start: true}") | ||
private boolean syncAutoStart; | ||
@Value("${store.event-publisher-id: 1}") | ||
private Long eventPublisherId; | ||
|
||
@EventListener | ||
public void initialize(ApplicationReadyEvent applicationReadyEvent) { | ||
long slotHeight = blockRepository.getSlotHeight().orElse(0L); | ||
|
||
if (slotHeight == 0) { | ||
if (!syncAutoStart) { | ||
startService.start(); | ||
} | ||
return; | ||
} | ||
|
||
Cursor currentCursor = cursorService.getCursor().orElse(null); | ||
if (currentCursor != null && currentCursor.getSlot() > slotHeight) { | ||
log.info("Delete cursors with slot greater than {}", slotHeight); | ||
cursorStorage.deleteBySlotGreaterThan(eventPublisherId, slotHeight); | ||
} | ||
|
||
if (!syncAutoStart) { | ||
startService.start(); | ||
} | ||
} | ||
} |
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
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