AnyJobProcessor
open class AnyJobProcessor<HandlingJob: QueueJob>: JobProcessor
A type-erased wrapper for a JobProcessor. Use this if you need to define an argument of a JobProcessor, or if you need to store a JobProcessor as a property.
Examples:
struct MyJobType: QueueJob { ... }
var persister: AnyJobProcessor<MyJobType>
func someFunc(usingProcessor: AnyJobPersister<MyJobType>)
-
The expected QueueJob type this erasure is wrapping
Declaration
Swift
public typealias JobType = HandlingJob
-
Creates a new wrapper for the given
JobPersister
Declaration
Swift
public init<P: JobProcessor>(_ processor: P) where P.JobType == HandlingJob
-
Processes a job of the given type using the internal
JobProcessor
. If the job fails to process for any reason theError
must be provided.Important
If thecompletion
is called with anError
, and theJobQueue
has aJobRetryStrategy
, then the job will be requeued. Otherwise the job will be purged from the JobQueue.Declaration
Swift
public func processJob(_ job: HandlingJob, completion: @escaping ((HandlingJob, Error?) -> Void))
Parameters
job
The QueueJob to be processed
completion
The block to be called when the job has completed processing. The function must be called and should be provided the original
job
that was provided to the processor. If the JobProcessor fails to process thejob
, then the JobProcessor must provide anError
to the receiver.