Skip to content

Instantly share code, notes, and snippets.

@pgressa
Created March 21, 2022 14:24
Show Gist options
  • Select an option

  • Save pgressa/4bb5eca31bf47b1ca773147411ef87c3 to your computer and use it in GitHub Desktop.

Select an option

Save pgressa/4bb5eca31bf47b1ca773147411ef87c3 to your computer and use it in GitHub Desktop.

Revisions

  1. pgressa created this gist Mar 21, 2022.
    25 changes: 25 additions & 0 deletions how.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@

    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()
    })

    }


    }