Created
March 21, 2022 14:24
-
-
Save pgressa/4bb5eca31bf47b1ca773147411ef87c3 to your computer and use it in GitHub Desktop.
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
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