Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@monitorjbl
Copy link
Contributor

Fix for #75. Got rid of the controller and made it into a Quartz job with a configurable frequency. Also added an option to make the index sync on startup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt possible to use the environment inside of the frequency method of the controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, no. This appears to be called by the vRaptor-quartz library entirely outside of the CDI. All @Injected fields are null when this is called.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-(
I think its because vraptor-quartzjob is building the task instance through
reflection in this class:
https://github.com/caelum/vraptor-quartzjob/blob/master/src/main/java/br/com/caelum/vraptor/quartzjob/QuartzScheduler.java#L108
.

But I think it should be possible to get the controller instance using
CDI's api. I'll take at the plugin later.

For now your solution is fine, then.

Chico Sokol

On Mon, Sep 29, 2014 at 2:52 PM, monitorjbl [email protected]
wrote:

In src/main/java/org/mamute/search/IndexSyncJob.java:

  • public void onStartup(@observes InterceptorsReady init) {
  •   if (Boolean.parseBoolean(environment.get("solr.syncOnStartup"))) {
    
  •       execute();
    
  •   }
    
  • }
  • /**
  • * Grabs the frequency of the job (bit of a hack to get things in the
  • * correct scope)
  • */
  • @ApplicationScoped
  • static class FrequencyInit {
  •   @Inject private Environment environment;
    
  •   public void onStartup(@Observes VRaptorInitialized init) {
    
  •       frequency = environment.get("solr.syncJob", DEFAULT_SYNC);
    

Sadly, no. This appears to be called by the vRaptor-quartz library
entirely outside of the CDI. All @injected fields are null when this is
called.


Reply to this email directly or view it on GitHub
https://github.com/caelum/mamute/pull/79/files#r18186341.

@monitorjbl
Copy link
Contributor Author

I pulled the CronTask bit into a separate controller class, it was too messy to keep all the pieces together since they each needed a separate context. The job part is now a singleton (@ApplicationScoped) that creates/destroys the Hibernate session on execution. The CronTask part is now a controller and is request scoped.

@monitorjbl
Copy link
Contributor Author

Hard-coded the frequency to get around the scoping issues with Quartz for now. I think the rest of the design is what's intended with vRaptor: a request-scoped controller for Quartz and an application-scoped singleton with the job execution logic.

@monitorjbl
Copy link
Contributor Author

Removed CronTask interface from IndexSyncController for now. The endpoint is still exposed, so manual syncing is still possible.

leocwolter added a commit that referenced this pull request Sep 30, 2014
@leocwolter leocwolter merged commit 1034462 into caelum:master Sep 30, 2014
@leocwolter
Copy link
Contributor

Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's missing the field visibility (private)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants