Skip to content

Commit

Permalink
Require id parameter in registerJob (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Mar 11, 2024
1 parent 5dbdee8 commit 0d5bf5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit 0d5bf5b

Please sign in to comment.