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 a default JobQueue Implementation using Postgres #29479

Closed
Tracked by #29474
fabrizzio-dotCMS opened this issue Aug 6, 2024 · 1 comment · Fixed by #30175
Closed
Tracked by #29474

Create a default JobQueue Implementation using Postgres #29479

fabrizzio-dotCMS opened this issue Aug 6, 2024 · 1 comment · Fixed by #30175

Comments

@fabrizzio-dotCMS
Copy link
Contributor

Parent Issue

#29474

Task

As a developer, I need to create a default implementation of the JobQueue interface using PostgreSQL. This implementation should handle the core functionalities of enqueuing jobs, retrieving job status, canceling jobs, and retrying jobs. The job details, including parameters and results, should be stored in PostgreSQL using JSONB fields. This will serve as the backbone of the job management system, ensuring that jobs are reliably managed and tracked within the database.

Consider the tech details shared in this video about https://learn.microsoft.com/en-us/shows/citus-con-postgres-2022/queues-in-postgresql
and https://www.2ndquadrant.com/en/blog/what-is-select-skip-locked-for-in-postgresql-9-5/
about SELECT FOR UPDATE and SKIP LOCKED

Proposed Objective

Core Features

Proposed Priority

Priority 3 - Average

Acceptance Criteria

  1. Schema Design: Define the PostgreSQL schema to store job details.
    1.1 A table of jobs should be created with columns for job ID, status, parameters, results, progress, and execution node.

  2. Enqueue Job: Implement the method to insert a new job into the jobs table.
    2.1. The job should be assigned a unique ID and initial status.
    2.2 Parameters should be stored in a JSON field.

  3. Retrieve Job Status: Implement the method to retrieve the status of a job from the jobs table.
    3.1 The status should include progress and the node executing the job.

  4. Cancel Job: Implement the method to update the status of a job to "canceled" in the jobs table.
    4.1. Ensure that running jobs can be identified and canceled appropriately.

  5. Retry Job: Implement the method to reset the status of a failed job to "pending" and re-enqueue it.
    5.1. Ensure the job is processed again from the beginning.

  6. Error Handling: Ensure that all database operations handle errors gracefully and log appropriate messages.

  7. Documentation: Provide documentation on how the PostgresJobQueue implementation interacts with the PostgreSQL database.

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

No response

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

@jgambarios jgambarios self-assigned this Sep 11, 2024
@nollymar nollymar removed the Triage label Sep 11, 2024
jgambarios added a commit that referenced this issue Sep 13, 2024
Introduced multiple job lifecycle event classes including `JobCreatedEvent`, `JobStartedEvent`, `JobProgressUpdatedEvent`, `JobCompletedEvent`, `JobFailedEvent`, and `JobCancelledEvent`. Updated `JobQueueManagerAPIImpl` to fire these events at appropriate stages in the job lifecycle to enhance observability and event-driven processing. Updated tests to accommodate the changes in event handling.
jgambarios added a commit that referenced this issue Sep 13, 2024
Replaced jobId strings with Job objects in event classes to simplify data access and reduce redundancy. Introduced RealTimeJobMonitor for handling real-time job updates, improving event notification efficiency and code maintainability. Updated tests and related classes to accommodate these changes.
jgambarios added a commit that referenced this issue Sep 13, 2024
Remove the `JobResult` enum and update job processing methods to use an `AbstractJobResult` interface. This refactor centralizes job result handling, differentiates success, failure, and cancellation cases, and incorporates metadata and error details within the job result.
jgambarios added a commit that referenced this issue Sep 18, 2024
This commit adds a PostgreSQL-specific implementation of the JobQueue interface, providing detailed methods for job management using a PostgreSQL database. It also introduces new error handling classes like JobQueueException, JobQueueDataException, and renames ProcessorNotFoundException to JobProcessorNotFoundException for clarity.
jgambarios added a commit that referenced this issue Sep 18, 2024
Updated job queries to use common table expressions (CTEs) for pagination, ensuring all job retrieval methods now return a JobPaginatedResult object containing job data and pagination details. This improves the consistency and handling of job data across the application. Added new tests to verify the correctness of these changes.
jgambarios added a commit that referenced this issue Sep 18, 2024
Moved job result set mapping logic from `PostgresJobQueue` to new `DBJobTransformer` utility class. This change improves code modularity, readability, and maintainability by isolating the transformation logic in a dedicated class.
jgambarios added a commit that referenced this issue Sep 19, 2024
jgambarios added a commit that referenced this issue Sep 20, 2024
Implemented a public getter method for JobQueue in JobQueueManagerAPI. Updated corresponding tests to include assertions for the new method. This enhances testability and ensures the JobQueue dependency is correctly injected.
jgambarios added a commit that referenced this issue Sep 25, 2024
Decoupled job cancellation logic by introducing a `Cancellable` interface. This improves clarity and separation of concerns, ensuring only processors capable of cancellation implement the relevant method. Updated existing tests to support the new interface and ensured compatibility with the JobQueueManagerAPI.
jgambarios added a commit that referenced this issue Sep 26, 2024
Decoupled job cancellation logic by introducing a `Cancellable` interface. This improves clarity and separation of concerns, ensuring only processors capable of cancellation implement the relevant method. Updated existing tests to support the new interface and ensured compatibility with the JobQueueManagerAPI.
jgambarios added a commit that referenced this issue Sep 26, 2024
Introduce markAsRunning() method to standardize setting job states to RUNNING. Replace usage of lastRetryTimestamp with completedAt for retry timing. Update tests to reflect changes and improve code readability. Ensure jobs are correctly re-queued with updated states.
jgambarios added a commit that referenced this issue Sep 26, 2024
jgambarios added a commit that referenced this issue Sep 27, 2024
jgambarios added a commit that referenced this issue Sep 27, 2024
jgambarios added a commit that referenced this issue Sep 27, 2024
jgambarios added a commit that referenced this issue Sep 27, 2024
@nollymar
Copy link
Contributor

This change will be tested after finishing this implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants