diff --git a/Sources/Jobs/AnyJob.swift b/Sources/Jobs/AnyJob.swift index a7a646a..49d6445 100644 --- a/Sources/Jobs/AnyJob.swift +++ b/Sources/Jobs/AnyJob.swift @@ -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 + func error(_ context: JobContext, _ error: Error, _ storage: JobStorage) -> EventLoopFuture } diff --git a/Sources/Jobs/Job.swift b/Sources/Jobs/Job.swift index b8e6211..e64c709 100644 --- a/Sources/Jobs/Job.swift +++ b/Sources/Jobs/Job.swift @@ -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 + func error(_ context: JobContext, _ error: Error, _ data: Data) -> EventLoopFuture } public extension Job { @@ -34,10 +34,19 @@ public extension Job { } /// See `Job.error` - func error(_ context: JobContext, _ error: Error) -> EventLoopFuture { + func error(_ context: JobContext, _ error: Error, _ data: Data) -> EventLoopFuture { return context.eventLoop.future() } + func error(_ context: JobContext, _ error: Error, _ storage: JobStorage) -> EventLoopFuture { + 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 { do { diff --git a/Sources/Jobs/JobsCommand.swift b/Sources/Jobs/JobsCommand.swift index 660114e..d730ae7 100644 --- a/Sources/Jobs/JobsCommand.swift +++ b/Sources/Jobs/JobsCommand.swift @@ -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) } } }