Skip to content

Commit

Permalink
Change signature of onRemove to forward job result (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas34 authored Dec 14, 2017
1 parent e551db3 commit bab6ab9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/SwiftQueue/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ public protocol Job {
func onRetry(error: Swift.Error) -> RetryConstraint

/// Job is removed from the queue and will never run again
func onRemove(error: Swift.Error?)
func onRemove(result: JobCompletion)

}
5 changes: 3 additions & 2 deletions Sources/SwiftQueue/SwiftQueueJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal final class SwiftQueueJob: Operation, JobResult {
internal func abort(error: Swift.Error) {
lastError = error
// Need to be called manually since the task is actually not in the queue. So cannot call cancel()
handler.onRemove(error: error)
handler.onRemove(result: .fail(error))
}

internal func run() {
Expand Down Expand Up @@ -105,7 +105,8 @@ internal final class SwiftQueueJob: Operation, JobResult {
}

internal func remove() {
handler.onRemove(error: lastError)
let result = lastError.map(JobCompletion.fail) ?? JobCompletion.success
handler.onRemove(result: result)
}

func done(_ result: JobCompletion) {
Expand Down
11 changes: 8 additions & 3 deletions Tests/SwiftQueueTests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ class TestJob: Job {
return retryConstraint
}

func onRemove(error: Error?) {
if error == nil {
func onRemove(result: JobCompletion) {
switch result {
case .success:
onCompleteCalled += 1
semaphore.signal()
} else {
break

case .fail:
onCancelCalled += 1
semaphore.signal()
break

}
}

Expand Down

0 comments on commit bab6ab9

Please sign in to comment.