-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add protocol for drivers that store their jobs in a queryable manner #120
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
Draft
Joannis
wants to merge
1
commit into
main
Choose a base branch
from
jo/queryable-jobs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // | ||
| // This source file is part of the Hummingbird server framework project | ||
| // Copyright (c) the Hummingbird authors | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| /// A protocol that extends `JobQueueDriver` by providing the ability to | ||
| /// query and iterate over jobs in the queue matching specific criteria. | ||
| /// | ||
| /// Conformers must implement a method to perform an async operation for | ||
| /// each job that matches a given `JobQueueQuery`. | ||
| public protocol QueryableJobQueueDriver: JobQueueDriver { | ||
| /// Iterates over each job of the given type matching the provided query, | ||
| /// performing the specified operation for each. | ||
| /// | ||
| /// - Parameters: | ||
| /// - type: The type of the parameters for the job. This is used for type safety and decoding. | ||
| /// - query: A `JobQueueQuery` that specifies which jobs to include. | ||
| /// - perform: A closure that is called with the job's ID and data for each matched job. | ||
| func withEachJob<Parameters: Sendable>( | ||
| ofType type: Parameters.Type, | ||
| matching query: JobQueueQuery<Parameters>, | ||
| perform: @Sendable @escaping (JobID, JobInstanceData<Parameters>) async throws -> Void | ||
| ) async throws | ||
| } | ||
|
|
||
| /// Default implementation for `withEachJob` that includes all jobs of the given type, | ||
| /// using the default query options. | ||
| extension QueryableJobQueueDriver { | ||
| /// Iterates over each job of the specified type using the default `JobQueueQuery` options, | ||
| /// performing the operation for each. | ||
| /// | ||
| /// - Parameters: | ||
| /// - type: The type of the parameters for the job. | ||
| /// - perform: A closure called for each job. | ||
| public func withEachJob<Parameters: Sendable>( | ||
| ofType type: Parameters.Type, | ||
| perform: @Sendable @escaping (JobID, JobInstanceData<Parameters>) async throws -> Void | ||
| ) async throws { | ||
| try await withEachJob( | ||
| ofType: Parameters.self, | ||
| matching: JobQueueQuery<Parameters>() | ||
| ) { id, job in | ||
| try await perform(id, job) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Represents a set of options for filtering and querying jobs in the job queue. | ||
| public struct JobQueueQuery<Parameters: Sendable>: Sendable { | ||
| /// Whether to include cancelled jobs in the query result. Defaults to `true`. | ||
| public var includeCancelledJobs = true | ||
| /// Whether to include failed jobs in the query result. Defaults to `true`. | ||
| public var includeFailedJobs = true | ||
| /// Whether to include completed jobs in the query result. Defaults to `true`. | ||
| public var includeCompletedJobs = true | ||
| /// Whether to include delayed jobs in the query result. Defaults to `true`. | ||
| public var includeDelayedJobs = true | ||
|
|
||
| /// Creates a new `JobQueueQuery` with the default options, including all jobs. | ||
| public init() {} | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to include pending jobs (ie queued but not executed). I'd probably replace delayed with pending.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also filter on
queuedAtand a couple other properties. Not sure what we all should supportThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these filters could be quite hard for the valkey solution. It is not a bunch of database tables. The Postgres solution will be happy to supply anything I'm sure, given it two tables (the queue and the jobs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does have a historic record. The problem with valkey is that some of the more complex queries you can do with postgres are not so easily available. I don't think we even include queuedAt in the valkey data. We could do that, I just added a hash map for each job which can hold arbitrary data.
If the valkey installation include Valkey search you can search hash maps