Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Migrate JobProcessor Discovery from Jandex to CDI #30545

Open
Tracked by #29474
jgambarios opened this issue Nov 1, 2024 · 2 comments · Fixed by #30898 or #30996
Open
Tracked by #29474

Refactor: Migrate JobProcessor Discovery from Jandex to CDI #30545

jgambarios opened this issue Nov 1, 2024 · 2 comments · Fixed by #30898 or #30996

Comments

@jgambarios
Copy link
Contributor

jgambarios commented Nov 1, 2024

Parent Issue

#29474

Task

Overview

Replace the current Jandex-based JobProcessor discovery mechanism with a standard CDI-based approach to improve maintainability and align with Java EE standards.

Current Implementation

The JobProcessorScanner class currently:

  • Uses Jandex index to scan for JobProcessor implementations
  • Requires manual class instantiation testing
  • Needs explicit registration with JobQueueManagerAPI
  • Depends on a static index file (META-INF/jandex.idx)

Proposed Changes

  1. Remove Jandex-based scanning mechanism
  2. Convert JobProcessor implementations to CDI beans
  3. Implement CDI-based discovery using @Inject Instance<JobProcessor>
  4. Leverage CDI events for processor registration
  5. Update JobQueueHelper to use CDI discovery

Benefits

  • Standard Java EE component discovery
  • Automatic dependency injection
  • Improved testability
  • Better integration with existing CDI infrastructure
  • Reduced manual error-prone operations
  • More maintainable codebase

Technical Details

Files to Modify

  • com.dotcms.jobs.business.api.JobProcessorScanner
  • com.dotcms.jobs.business.api.JobProcessorFactory
  • com.dotcms.jobs.business.processor.JobProcessor
  • com.dotcms.rest.api.v1.job.JobQueueHelper

Implementation Steps

  1. Add CDI qualifier annotations if needed for specific processor types
  2. Update JobProcessor interface with appropriate CDI annotations
  3. Modify JobQueueHelper to use CDI for processor discovery
  4. Remove Jandex-specific code and dependencies
  5. Update documentation
  6. Add/update unit tests

Proposed Objective

Core Features

Proposed Priority

Priority 2 - Important

@fabrizzio-dotCMS
Copy link
Contributor

fabrizzio-dotCMS commented Dec 13, 2024

I confirmed that the discovery process no longer relies on the Jandex index. A new restriction has been introduced, requiring beans to have the “Dependent” scope, ensuring a unique and independent instance per job—which is reasonable.

However, this restriction introduces a validation step that throws an exception if a non-dependent bean is detected. This behavior disrupts the entire queue subsystem. Implementing a non-disruptive mechanism to log an exception when an unsuitable bean is marked as a Queue candidate would be highly beneficial. This would allow the system to report the issue while keeping the remaining valid queues functional and available.
Here some screenshots showing what it looks like when an invalid bean is found.
Screenshot 2024-12-13 at 11 43 27 AM

I introduced a bean annotated with @Queue and @ApplicationScoped, and I noticed that initialization starts from the servlet. However, when the detection process begins and encounters an invalid bean, the registration breaks, causing the rest of the system to stop functioning.

@fabrizzio-dotCMS fabrizzio-dotCMS moved this from Internal QA to Current Sprint Backlog in dotCMS - Product Planning Dec 13, 2024
@fabrizzio-dotCMS fabrizzio-dotCMS removed their assignment Dec 13, 2024
@yolabingo yolabingo moved this from Current Sprint Backlog to In Review in dotCMS - Product Planning Dec 19, 2024
@jgambarios jgambarios self-assigned this Dec 20, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in dotCMS - Product Planning Dec 20, 2024
@jgambarios jgambarios reopened this Dec 20, 2024
@github-project-automation github-project-automation bot moved this from Done to Current Sprint Backlog in dotCMS - Product Planning Dec 20, 2024
@jgambarios jgambarios moved this from Current Sprint Backlog to Internal QA in dotCMS - Product Planning Dec 20, 2024
@jgambarios jgambarios removed their assignment Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment