Skip to content

Instantly share code, notes, and snippets.

@pgressa
Created March 21, 2022 14:24
Show Gist options
  • Save pgressa/4bb5eca31bf47b1ca773147411ef87c3 to your computer and use it in GitHub Desktop.
Save pgressa/4bb5eca31bf47b1ca773147411ef87c3 to your computer and use it in GitHub Desktop.
public class MicronautFactory {
private final ApplicationContext context = ApplicationContext.run();
public TaskScheduler getTaskScheduler() {
return context.getBean(TaskScheduler.class, Qualifiers.byName(TaskExecutors.SCHEDULED));
}
}
public class HowToFetchTaskScheduler {
public String createTask(TaskDefinition definition){
....
Class<Job> jobClass = .....;
TaskScheduler taskScheduler = MicronautFactory.getTaskScheduler();
taskSchedler.schedule(cronExpression, () -> {
Job jobFromClass = jobClass.newInstance();
jobFromClass.execute()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment