Is there a way to call a spring scheduled method (job) through a user interaction? I need to create a table with shown all jobs and the user should be able to execute them manually. For sure the jobs run automatically but the user should be able to start them manually.
@Configuration
@EnableScheduling
public class ScheduleConfiguration {
@Bean
public ScheduledLockConfiguration taskScheduler(LockProvider
lockProvider) {
return ScheduledLockConfigurationBuilder
.withLockProvider(lockProvider)
.withPoolSize(15)
.withDefaultLockAtMostFor(Duration.ofHours(3))
.build();
}
@Bean
public LockProvider lockProvider(DataSource dataSource) {
return new JdbcTemplateLockProvider(dataSource);
}
}
@Component
public class MyService {
@Scheduled(fixedRateString = "1000")
@SchedulerLock(name = "MyService.process", lockAtLeastFor = 30000)
@Transactional
public void process() {
// do something
}
}