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
Jobs Refactor #391
Jobs Refactor #391
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x.x #391 +/- ##
==========================================
+ Coverage 84.39% 84.46% +0.06%
==========================================
Files 94 99 +5
Lines 5282 5342 +60
==========================================
+ Hits 4458 4512 +54
- Misses 824 830 +6 ☔ View full report in Codecov by Sentry. |
For reference this is what the Jobs framework did previously with comment indicating the issue I'm trying to fix let see = SES()
struct EmailJob: HBJob {
let recipient: String
let subject: String
let message: String
func execute(logger: Logger) async throws {
// How do I get access to ses to send the email here?
// I can't include it in the init as the job is recreated by queue
// at a later date, I can't use variable capture as I would in a closure
}
}
EmailJob.register()
// Create job queue
let jobQueue = HBRedisJobQueue()
jobQueue.push(EmailJob(recipient: "adam@gmail.com", subject:"Test", message: "Testing, testing, 123")) |
func onInit() async throws | ||
/// Push Job onto queue | ||
/// - Returns: Identifier of queued job | ||
func push(data: Data) async throws -> JobID |
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.
Is there a reason we're using Data
here, instead of ByteBuffer
?
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.
Just the fact we are moving back and forward between the two types. Should probably change to ByteBuffer.
func shutdownGracefully() async | ||
@discardableResult public func push<Parameters: Codable & Sendable>(id: HBJobIdentifier<Parameters>, parameters: Parameters) async throws -> Queue.JobID { | ||
let jobRequest = HBJobRequest(id: id, parameters: parameters) | ||
let data = try JSONEncoder().encode(jobRequest) |
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.
Would it be possible to allow drivers to encode these parameters (or the request as a whole)? In MongoDB, it would be really unfortunate to encode this to JSON, then add the JSON into MongoDB. Since MongoDB already has (recursive) object support. So it would be able to store this as-is in BSON. Encoding to JSON would prevent indexes from being applies to id
, and inspecting the data in MongoDB would require quite a lot of work from the developer.
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.
The idea is that the driver only stores data blobs. Do you see an advantage to storing the full object structure? I guess debugging job issues might be easier.
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.
Debugging mainly, yes
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.
I had moved away from the allowing drivers to do the encoding because I was repeating the same code across all of the drivers. It also meant the driver needed to know about the job registry so they could be sure to decode the correct job type. Data blobs meant the driver had a clean split from the job decoding. I'll have another look though.
This refactor is required as it has been pointed out accessing services from a job is quite hard with the current structure. The changes include a breaking up of what defines a job and an actual job instance with parameters. I've also added a JobIdentifier which also includes a reference to the parameter type used by the job to ensure we don't pass bad parameters to a job.