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

Require id parameter in registerJob #397

Merged
merged 2 commits into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/HummingbirdJobs/JobQueue.swift
Expand Up @@ -55,7 +55,7 @@ public struct JobQueue<Queue: JobQueueDriver>: Service {
/// - maxRetryCount: Maximum number of times job is retried before being flagged as failed
/// - execute: Job code
public func registerJob<Parameters: Codable & Sendable>(
_ id: JobIdentifier<Parameters>,
id: JobIdentifier<Parameters>,
maxRetryCount: Int = 0,
execute: @escaping @Sendable (
Parameters,
Expand Down
10 changes: 5 additions & 5 deletions Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift
Expand Up @@ -92,7 +92,7 @@ final class HummingbirdJobsTests: XCTestCase {
let expectation = XCTestExpectation(description: "TestJob.execute was called", expectedFulfillmentCount: 10)

let jobQueue = JobQueue(.memory, numWorkers: 4, logger: Logger(label: "HummingbirdJobsTests"))
jobQueue.registerJob(jobIdentifer) { parameters, context in
jobQueue.registerJob(id: jobIdentifer) { parameters, context in
let runningJobs = runningJobCounter.wrappingIncrementThenLoad(by: 1, ordering: .relaxed)
if runningJobs > maxRunningJobCounter.load(ordering: .relaxed) {
maxRunningJobCounter.store(runningJobs, ordering: .relaxed)
Expand Down Expand Up @@ -132,7 +132,7 @@ final class HummingbirdJobsTests: XCTestCase {
MemoryQueue { _, _ in failedJobCount.wrappingIncrement(by: 1, ordering: .relaxed) },
logger: logger
)
jobQueue.registerJob(jobIdentifer, maxRetryCount: 3) { _, _ in
jobQueue.registerJob(id: jobIdentifer, maxRetryCount: 3) { _, _ in
expectation.fulfill()
throw FailedError()
}
Expand All @@ -152,7 +152,7 @@ final class HummingbirdJobsTests: XCTestCase {
let expectation = XCTestExpectation(description: "TestJob.execute was called")
let jobIdentifer = JobIdentifier<TestJobParameters>(#function)
let jobQueue = JobQueue(.memory, numWorkers: 1, logger: Logger(label: "HummingbirdJobsTests"))
jobQueue.registerJob(jobIdentifer) { parameters, _ in
jobQueue.registerJob(id: jobIdentifer) { parameters, _ in
XCTAssertEqual(parameters.id, 23)
XCTAssertEqual(parameters.message, "Hello!")
expectation.fulfill()
Expand Down Expand Up @@ -181,7 +181,7 @@ final class HummingbirdJobsTests: XCTestCase {
numWorkers: 4,
logger: logger
)
jobQueue.registerJob(jobIdentifer) { _, _ in
jobQueue.registerJob(id: jobIdentifer) { _, _ in
expectation.fulfill()
try await Task.sleep(for: .milliseconds(1000))
}
Expand Down Expand Up @@ -214,7 +214,7 @@ final class HummingbirdJobsTests: XCTestCase {
var logger = Logger(label: "HummingbirdJobsTests")
logger.logLevel = .debug
let jobQueue = JobQueue(.memory, numWorkers: 1, logger: Logger(label: "HummingbirdJobsTests"))
jobQueue.registerJob(jobIdentifer2) { parameters, _ in
jobQueue.registerJob(id: jobIdentifer2) { parameters, _ in
string.withLockedValue { $0 = parameters }
expectation.fulfill()
}
Expand Down