Skip to content

Commit

Permalink
add job data to error call
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmcd committed Feb 6, 2019
1 parent 25bfcec commit 8116ca6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Sources/Jobs/AnyJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public protocol AnyJob {
/// - Parameters:
/// - context: The context for the job
/// - error: The error thrown
/// - storage: The JobStorage
/// - Returns: A future void, signifying completion
func error(_ context: JobContext, _ error: Error) -> EventLoopFuture<Void>
func error(_ context: JobContext, _ error: Error, _ storage: JobStorage) -> EventLoopFuture<Void>
}
13 changes: 11 additions & 2 deletions Sources/Jobs/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public protocol Job: AnyJob {
/// - context: The JobContext. Can be used to store and retrieve services
/// - error: The error returned by the job.
/// - Returns: A future `Void` value used to signify completion
func error(_ context: JobContext, _ error: Error) -> EventLoopFuture<Void>
func error(_ context: JobContext, _ error: Error, _ data: Data) -> EventLoopFuture<Void>
}

public extension Job {
Expand All @@ -34,10 +34,19 @@ public extension Job {
}

/// See `Job.error`
func error(_ context: JobContext, _ error: Error) -> EventLoopFuture<Void> {
func error(_ context: JobContext, _ error: Error, _ data: Data) -> EventLoopFuture<Void> {
return context.eventLoop.future()
}

func error(_ context: JobContext, _ error: Error, _ storage: JobStorage) -> EventLoopFuture<Void> {
do {
let data = try JSONDecoder().decode(Data.self, from: storage.data)
return self.error(context, error, data)
} catch {
return context.eventLoop.future(error: error)
}
}

/// See `AnyJob.anyDequeue`
public func anyDequeue(_ context: JobContext, _ storage: JobStorage) -> EventLoopFuture<Void> {
do {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Jobs/JobsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public class JobsCommand: Command {
.persistenceLayer
.completed(key: key, jobStorage: jobStorage)
.flatMap { _ in
return job.error(jobContext, error)
return job.error(jobContext, error, jobStorage)
}
}
}
Expand Down

0 comments on commit 8116ca6

Please sign in to comment.