Dropwizard Sundial Schedueled task with Hibernate object

105 Views Asked by At

I have this sundial task in my dropwizard project:

@SimpleTrigger(repeatInterval = 10, timeUnit = TimeUnit.SECONDS)
public class GitlabImporter extends Job {

private static BranchDAO branchDAO;

    @Override
    @ExceptionMetered
    public void doRun() throws JobInterruptException {

        branchDAO = (BranchDAO) SundialJobScheduler.getServletContext().getAttribute("BranchDAO");

        String jobId = UUID.randomUUID().toString();

        try {
            ...
            log.info(branches.toString());
        } catch (Exception e) {
            log.error(e.getLocalizedMessage());
        }
    }
}

I try to use my DAO in the Sceduler task, I wanted to follow the sundial documentation how to load objects but it seems not to work. What would be the correct way to use the Hibernate project in my Sundial task?

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

One way to achieve this is by setting the BranchDAO attribute in the YourDropwizardApplication class' run() method -

environment.getApplicationContext().setAttribute("BranchDAO", new BranchDAO());