-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Scheduler Name
Paul Sterl edited this page Jan 19, 2025
·
6 revisions
To customize the way how the default SchedulerService
is build the SchedulerCustomizer
interface can be used.
One possible way could be just to use a random string for each instance, which will change on each restart.
@Bean
SchedulerCustomizer schedulerCustomizer(Environment env) {
return new SchedulerCustomizer() {
public String name() {
var hostname = UUID.randomUUID().toString().substring(0, 8);
hostname = String.join("-", env.getActiveProfiles()) + "-" + hostname;
return hostname;
}
};
}
In this example we use the azure web-application environment variables to set the scheduler name:
@Bean
SchedulerCustomizer schedulerCustomizer(Environment env) {
return new SchedulerCustomizer() {
public String name() {
var hostname = env.getProperty("WEBSITE_INSTANCE_ID");
var role = env.getProperty("APPSETTING_APPLICATIONINSIGHTS_ROLE_NAME", "").toLowerCase();
if (role != "") {
hostname = hostname + "-" + role;
}
return hostname;
}
};
}