-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
initializer/src/main/java/dasniko/keycloak/initializer/timer/TimerInitializerProvider.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,35 @@ | ||
package dasniko.keycloak.initializer.timer; | ||
|
||
import com.google.auto.service.AutoService; | ||
import dasniko.keycloak.initializer.InitializerProviderFactory; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.keycloak.Config; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.models.utils.KeycloakModelUtils; | ||
import org.keycloak.timer.TimerProvider; | ||
|
||
@Slf4j | ||
@AutoService(InitializerProviderFactory.class) | ||
public class TimerInitializerProvider implements InitializerProviderFactory { | ||
|
||
public static final String PROVIDER_ID = "timer"; | ||
|
||
private static Long interval; | ||
|
||
@Override | ||
public void init(Config.Scope config) { | ||
interval = config.getLong("interval", 60000L); | ||
} | ||
@Override | ||
public void postInit(KeycloakSessionFactory factory) { | ||
KeycloakModelUtils.runJobInTransaction(factory, session -> { | ||
TimerProvider timerProvider = session.getProvider(TimerProvider.class); | ||
timerProvider.schedule(() -> log.info("Timer is being executed..."), interval, PROVIDER_ID); | ||
}); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return PROVIDER_ID; | ||
} | ||
} |