Skip to content

Commit

Permalink
timer in enableable
Browse files Browse the repository at this point in the history
  • Loading branch information
dasniko committed Feb 21, 2024
1 parent 7e0a78a commit 8a7f56c
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ public class TimerInitializerProvider implements InitializerProviderFactory {

public static final String PROVIDER_ID = "timer";

private static boolean enabled;
private static Long interval;

@Override
public void init(Config.Scope config) {
enabled = config.getBoolean("enabled", false);
interval = config.getLong("interval", 60000L);
}
@Override
public void postInit(KeycloakSessionFactory factory) {
log.info("{} is {}.", this.getClass().getSimpleName(), enabled ? "enabled" : "disabled");
if (!enabled)
return;

KeycloakModelUtils.runJobInTransaction(factory, session -> {
TimerProvider timerProvider = session.getProvider(TimerProvider.class);
timerProvider.schedule(() -> log.info("Timer is being executed..."), interval, PROVIDER_ID);
Expand Down

0 comments on commit 8a7f56c

Please sign in to comment.