@alfranke: I’m hoping you can help me with this.
I’m facing a roadblock where I have cohort generation working as a Tasklet (using the example application job service that uses Tasklets), but now I’d like to be able to manipulate the cohrot definition via CohortDefinitionRepository during the task execution. The steps would go like this:
- Load Cohort Definition
- Set generation status to RUNNING **
- Build cohort definition query
- Execute query
- Set generation Status to COMPLETE **
The ** represents where I’d want to cohortDefRepo.save(definition) after modifying the generation status.
My understanding about spring is: In order to inject the repository using @Autowired, the class has to be annotiated by some type of @Component annotation (or @Component itself). I tried doing this and got an exception that no default constructor was defined in the Tasklet. Which reminded me that we’re not using Spring injections at all when kicking off the job: we’re creating instances ourselves that spring knows nothing about.
So, I feel like a design change is required when dealing with Jobs. OR: I read that people that needed to to do this sort of thing encapsulated the task logic in a separate bean (that would manage it’s own transactions because manipulaiting the repository will work in it’s own transactions cope, and I read there are special challenges related to transaction scopes when working inside Spring Batch). I just don’t know how’d access a bean from inside the tasklet.
I’d appreciate any help or advice you have on this.
-Chris