Sync-base: skip scheduled execution when app is not running

This commit is contained in:
2025-05-14 11:27:39 +02:00
parent 2206c13466
commit 84b1d57125
6 changed files with 16 additions and 6 deletions

View File

@@ -67,7 +67,7 @@ public class DeferredInvalidationQueueService implements PeerConnectedEventListe
/** /**
* Periodically returns deferred invalidations to the invalidation queue for all reachable hosts. * Periodically returns deferred invalidations to the invalidation queue for all reachable hosts.
*/ */
@Scheduled(every = "15s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) @Scheduled(every = "15s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class)
@Blocking @Blocking
void periodicReturn() { void periodicReturn() {
for (var reachable : reachablePeerManager.getAvailableHosts()) for (var reachable : reachablePeerManager.getAvailableHosts())

View File

@@ -15,7 +15,7 @@ public class PersistentStaticPeerDiscovery {
@Inject @Inject
PersistentPeerDataService persistentPeerDataService; PersistentPeerDataService persistentPeerDataService;
@Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) @Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class)
public void discoverPeers() { public void discoverPeers() {
var addrs = persistentPeerDataService.getPersistentPeerAddresses(); var addrs = persistentPeerDataService.getPersistentPeerAddresses();
for (var addr : addrs) { for (var addr : addrs) {

View File

@@ -25,7 +25,7 @@ public class StaticPeerDiscovery {
).toList(); ).toList();
} }
@Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) @Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class)
public void discoverPeers() { public void discoverPeers() {
for (var peer : _peers) { for (var peer : _peers) {
peerDiscoveryDirectory.notifyAddr(peer); peerDiscoveryDirectory.notifyAddr(peer);

View File

@@ -54,7 +54,7 @@ public class LocalPeerDiscoveryBroadcaster {
_socket.close(); _socket.close();
} }
@Scheduled(every = "${dhfs.objects.peerdiscovery.interval}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) @Scheduled(every = "${dhfs.objects.peerdiscovery.interval}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class)
public void broadcast() throws Exception { public void broadcast() throws Exception {
if (!enabled) { if (!enabled) {
return; return;

View File

@@ -30,7 +30,7 @@ public class PeerLastSeenUpdater {
@Inject @Inject
PersistentPeerDataService persistentPeerDataService; PersistentPeerDataService persistentPeerDataService;
@Scheduled(every = "${dhfs.objects.last-seen.update}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) @Scheduled(every = "${dhfs.objects.last-seen.update}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class)
@Blocking @Blocking
void update() { void update() {
var snapshot = reachablePeerManager.getHostStateSnapshot(); var snapshot = reachablePeerManager.getHostStateSnapshot();

View File

@@ -71,7 +71,7 @@ public class ReachablePeerManager {
_heartbeatExecutor = Executors.newVirtualThreadPerTaskExecutor(); _heartbeatExecutor = Executors.newVirtualThreadPerTaskExecutor();
} }
@Scheduled(every = "${dhfs.objects.reconnect_interval}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) @Scheduled(every = "${dhfs.objects.reconnect_interval}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class)
@Blocking @Blocking
public void tryConnectAll() { public void tryConnectAll() {
if (_heartbeatExecutor == null) return; if (_heartbeatExecutor == null) return;
@@ -158,6 +158,7 @@ public class ReachablePeerManager {
/** /**
* Checks if the given host is reachable. * Checks if the given host is reachable.
*
* @param host the host to check * @param host the host to check
* @return true if the host is reachable, false otherwise * @return true if the host is reachable, false otherwise
*/ */
@@ -167,6 +168,7 @@ public class ReachablePeerManager {
/** /**
* Checks if the given host is reachable. * Checks if the given host is reachable.
*
* @param host the host to check * @param host the host to check
* @return true if the host is reachable, false otherwise * @return true if the host is reachable, false otherwise
*/ */
@@ -176,6 +178,7 @@ public class ReachablePeerManager {
/** /**
* Gets the address of the given host. * Gets the address of the given host.
*
* @param host the host to get the address for * @param host the host to get the address for
* @return the address of the host, or null if not reachable * @return the address of the host, or null if not reachable
*/ */
@@ -185,6 +188,7 @@ public class ReachablePeerManager {
/** /**
* Gets the ids of all reachable hosts. * Gets the ids of all reachable hosts.
*
* @return a list of ids of all reachable hosts * @return a list of ids of all reachable hosts
*/ */
public List<PeerId> getAvailableHosts() { public List<PeerId> getAvailableHosts() {
@@ -193,6 +197,7 @@ public class ReachablePeerManager {
/** /**
* Gets a snapshot of current state of the connected (and not connected) peers * Gets a snapshot of current state of the connected (and not connected) peers
*
* @return information about all connected/disconnected peers * @return information about all connected/disconnected peers
*/ */
public HostStateSnapshot getHostStateSnapshot() { public HostStateSnapshot getHostStateSnapshot() {
@@ -205,6 +210,7 @@ public class ReachablePeerManager {
/** /**
* Removes the given host from the cluster * Removes the given host from the cluster
*
* @param peerId the id of the host to remove * @param peerId the id of the host to remove
*/ */
public void removeRemoteHost(PeerId peerId) { public void removeRemoteHost(PeerId peerId) {
@@ -216,6 +222,7 @@ public class ReachablePeerManager {
/** /**
* Selects the best address for the given host. * Selects the best address for the given host.
* The address is selected based on the type of the address. (with e.g. LAN address preferred over WAN) * The address is selected based on the type of the address. (with e.g. LAN address preferred over WAN)
*
* @param host the host to select the address for * @param host the host to select the address for
* @return the best address for the host, or null if not reachable * @return the best address for the host, or null if not reachable
*/ */
@@ -225,6 +232,7 @@ public class ReachablePeerManager {
/** /**
* Call the given peer and get its information. * Call the given peer and get its information.
*
* @param host the peer to get the information for * @param host the peer to get the information for
* @return the information about the peer * @return the information about the peer
*/ */
@@ -243,6 +251,7 @@ public class ReachablePeerManager {
/** /**
* Adds the given peer to the cluster. * Adds the given peer to the cluster.
* The certificate provided is verified against the one peer is using right now. * The certificate provided is verified against the one peer is using right now.
*
* @param host the peer to add * @param host the peer to add
* @param cert the certificate of the peer * @param cert the certificate of the peer
*/ */
@@ -264,6 +273,7 @@ public class ReachablePeerManager {
/** /**
* Gets the information about all reachable peers that are not added to the cluster. * Gets the information about all reachable peers that are not added to the cluster.
*
* @return a collection of pairs of peer id and peer info * @return a collection of pairs of peer id and peer info
*/ */
public Collection<Pair<PeerId, ApiPeerInfo>> getSeenButNotAddedHosts() { public Collection<Pair<PeerId, ApiPeerInfo>> getSeenButNotAddedHosts() {