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

Create Model and Classes Abstraction for Job Handling #29478

Closed
Tracked by #29474
fabrizzio-dotCMS opened this issue Aug 6, 2024 · 0 comments · Fixed by #29705
Closed
Tracked by #29474

Create Model and Classes Abstraction for Job Handling #29478

fabrizzio-dotCMS opened this issue Aug 6, 2024 · 0 comments · Fixed by #29705

Comments

@fabrizzio-dotCMS
Copy link
Contributor

fabrizzio-dotCMS commented Aug 6, 2024

Parent Issue

#29474

Task

We need to create the necessary models and classes. This includes defining the Job, JobManager JobProcessor, and queue service interfaces, as well as implementing a class representing The Concrete Job Logic passing the necessary parameters.
These classes should separate the core business logic from the service implementation. So that switching the implementation below can be easily accomplished without affecting or having to modify the upper layers.

Proposed Objective

Core Features

Proposed Priority

Priority 3 - Average

Acceptance Criteria

Create a Job class to encapsulate job details.
Create a JobProcessor class to handle job execution logic.
Create a JobQueueManager class with methods to manage and execute tasks, including progress tracking. This class serves as the template for concrete task implementation. e.g. An Import Content Task should implement this interface

These classes should serve as the entry point to establish communication between the rest endpoints and the low-level clases that take care of the job state and process.

e.g.

public interface Job {
    String id();
    String queueName();
    JobState state();
    LocalDateTime createdAt();
    LocalDateTime updatedAt();
    Optional<LocalDateTime> completedAt();
    Optional<JobResult> result();
    Map<String, Object> parameters();
    ....
}

public interface JobQueue {
    String addJob(String queueName, Map<String, Object> parameters);
    Job getJob(String jobId);
    List<Job> getActiveJobs(String queueName, int page, int pageSize);
    List<Job> getCompletedJobs(String queueName, LocalDateTime startDate, LocalDateTime endDate, int page, int pageSize);
    CompletableFuture<Job> watchJob(String jobId);
}

// JobProcessor.java
public interface JobProcessor {
    void processJob(Job job);
}

// JobQueueManager.java
public class JobQueueManager {
    private JobQueue jobQueue;
    private Map<String, JobProcessor> processors;
    private int threadPoolSize;

    // Constructor, getters, and setters

    public void start() {
        // Initialize thread pool and start processing jobs
    }

    public void stop() {
        // Stop processing jobs and shutdown thread pool
    }

   // EmailJobProcessor.java
public class EmailJobProcessor implements JobProcessor {
    @Override
    public void processJob(Job job) {
        Map<String, Object> params = job.getParameters();
        String to = (String) params.get("to");
        String subject = (String) params.get("subject");
        String body = (String) params.get("body");

        // Simulate sending an email
        System.out.println("Sending email to: " + to);
        System.out.println("Subject: " + subject);
        System.out.println("Body: " + body);

        // Simulate processing time
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

here's an example generated https://dotcms.slack.com/archives/CQNF9PCFQ/p1722964013379569

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

@fabrizzio-dotCMS fabrizzio-dotCMS changed the title Create Model and Classes for Job Handling and Service Implementation Create Model and Classes Abstraction for Job Handling and Service Aug 6, 2024
@fabrizzio-dotCMS fabrizzio-dotCMS changed the title Create Model and Classes Abstraction for Job Handling and Service Create Model and Classes Abstraction for Job Handling Aug 6, 2024
@jgambarios jgambarios self-assigned this Aug 19, 2024
@jgambarios jgambarios moved this from New to In Progress in dotCMS - Product Planning Aug 19, 2024
@nollymar nollymar removed the Triage label Aug 20, 2024
jgambarios added a commit that referenced this issue Aug 23, 2024
jgambarios added a commit that referenced this issue Aug 26, 2024
jgambarios added a commit that referenced this issue Aug 26, 2024
jgambarios added a commit that referenced this issue Aug 27, 2024
jgambarios added a commit that referenced this issue Aug 27, 2024
jgambarios added a commit that referenced this issue Aug 27, 2024
jgambarios added a commit that referenced this issue Aug 27, 2024
jgambarios added a commit that referenced this issue Aug 28, 2024
jgambarios added a commit that referenced this issue Aug 29, 2024
jgambarios added a commit that referenced this issue Aug 29, 2024
jgambarios added a commit that referenced this issue Aug 29, 2024
jgambarios added a commit that referenced this issue Aug 30, 2024
jgambarios added a commit that referenced this issue Aug 30, 2024
jgambarios pushed a commit that referenced this issue Sep 5, 2024
@github-project-automation github-project-automation bot moved this from In Review to Internal QA in dotCMS - Product Planning Sep 5, 2024
@jgambarios jgambarios moved this from Internal QA to Done in dotCMS - Product Planning Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants