Skip to content

Commit

Permalink
[ANCHOR-698] Enable PaymentObservingAccountsManager for SEP-31 only (#…
Browse files Browse the repository at this point in the history
…1366)

### Description

This PR add check to `ObservingAccountsBeans ` to check if SEP-31 is
enabled. In this case the bean is always created, but only activate if
SEP-31 is enabled.

This is because this bean is required in the presence for the creation
of `PaymentObserverBeans`. We can't simply use conditional annotation
that disable the bean's creation

### Context

The PaymentObseringAccountManager should only be restarted when needed.
Currently only SEP-31 requires the service.

### Testing

- `./gradlew test`
  • Loading branch information
JiahuiWho committed May 16, 2024
1 parent 0fc46d0 commit c333bd0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ InteractiveUrlConstructor interactiveUrlConstructor(
}

@Bean
@ConditionalOnAnySepsEnabled(seps = {"sep31"})
Sep31DepositInfoGenerator sep31DepositInfoGenerator(
Sep31Config sep31Config,
PaymentObservingAccountsManager paymentObservingAccountsManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.stellar.anchor.platform.observer.stellar.PaymentObservingAccountStore;
import org.stellar.anchor.platform.observer.stellar.PaymentObservingAccountsManager;

@Configuration
public class ObservingAccountsBeans {
private final Environment env;

public ObservingAccountsBeans(Environment env) {
this.env = env;
}

@Bean
public PaymentObservingAccountsManager paymentObservingAccountsManager(
PaymentObservingAccountStore paymentObservingAccountStore) {
return new PaymentObservingAccountsManager(paymentObservingAccountStore);
PaymentObservingAccountsManager bean =
new PaymentObservingAccountsManager(paymentObservingAccountStore);

if (env.getProperty("sep31.enabled", Boolean.class, false)) {
bean.start();
}

return bean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public void initialize() {
account.getAccount(), account.getLastObserved(), AccountType.TRANSIENT);
upsert(oa);
}
}

// Start the eviction task
public void start() {
Log.debug("Start the eviction task...");
ScheduledExecutorService scheduler = DaemonExecutors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(
this::evictAndPersist, 60, getEvictPeriod().getSeconds(), TimeUnit.SECONDS);
Expand Down

0 comments on commit c333bd0

Please sign in to comment.