JobQueue
open class JobQueue<Job: QueueJob>
An in-memory (with optional persistence) queue which can be processed by a JobProcessor
-
Defines the state of the queue.
See moreDeclaration
Swift
public enum State
-
Defines what to do in the case of jobs which failed to process. By default
retryStrategy
is nil, in which case failed jobs are simply removed from the queue.Declaration
Swift
public var retryStrategy: JobRetryStrategy?
-
Returns the current
JobQueue.State
of this instanceDeclaration
Swift
private(set) public var state: State
-
Gets the
JobProcessor
to process the jobs on this instance, if any; otherwisenil
.JobQueue
s without aJobProcessor
must manually process and remove jobs from the queue.Declaration
Swift
public var processor: AnyJobProcessor<Job>?
-
Gets the
JobPersister
to persist jobs in this queue, if one exists; otherwise nil. JobQueues that do not have aJobPersister
will be in-memory only.Declaration
Swift
public var persister: AnyJobPersister<Job>?
-
Initializes this JobQueue to handle the given type of Job
Throws
Throws if a JobPersister is provided and it fails to load its jobs.Declaration
Swift
public init(handling: Job.Type, name: String, persister: AnyJobPersister<Job>? = nil) throws
Parameters
handling
The expect type of QueueJob this JobQueue will handle
name
The name for this queue.
persister
A JobPersister that may be used to persist jobs.
-
Returns the number of jobs in this
JobQueue
awaiting processing.Declaration
Swift
public var count: Int
-
Adds the provided
jobs
to thisJobQueue
, while maintaining their order.Remark
This function is thread safe.Declaration
Swift
public func add(_ jobs: [Job])
Parameters
jobs
The jobs to be added to this
JobQueue
. -
Queues the provided
job
for immediate processing. That is, the provided job will be inserted at the very front of thisJobQueue
Remark
This function is thread safeDeclaration
Swift
public func retry(_ job: Job)
Parameters
job
The job to be inserted at the front of this
JobQueue
-
Attempts to return without removing the next
Job
at the front of thisJobQueue
.Remark
This function is thread safeDeclaration
Swift
public func peek() -> Job?
Return Value
The next
Job
at the front of thisJobQueue
, if one exists; otherwise nil -
Removes the next
Job
from the front of thisJobQueue
Remark
This function is thread safeDeclaration
Swift
public func remove() -> Job?
Return Value
The next
Job
at the front of thisJobQueue
, if one exists; otherwise nil -
Cancels the job in this
JobQueue
with the providedid
, if it exists.Attention
This cannot cancel a matchingJob
if thatJob
is already being processed.Remark
This function is thread safeDeclaration
Swift
public func cancel(_ id: String)
Parameters
id
The
id
of theJob
to be removed from thisJobQueue
-
Removes all jobs from this JobQueue
Remark
This function is thread safeDeclaration
Swift
public func drain()
-
Tells this
JobQueue
to start processing itsJob
sDeclaration
Swift
public func start()
-
Tells this
JobQueue
to stop processing itsJobs
.Declaration
Swift
public func stop()
-
Subscribes a listener to this
JobQueue
.Attention
The returned
JobQueueNotificationToken
isweak
, and must be strongly retained by the receiver. As soon as the token goes out of scope, or is set tonil
, the observer will no longer recieve notifications.Declaration
Swift
public func observe(_ block: @escaping (_ queue: JobQueue<Job>, _ jobs: [Job], _ event: JobQueueEvent) -> Void) -> JobQueueNotificationToken<Job>
Parameters
block
The function to be called which will receive the notification
queue
The
JobQueue
from which the notification is broadcastjobs
The jobs affected by the
JobQueueEvent
event
The
JobQueueEvent
(such as.added
,.removed
, etc) affecting the providedjobs
Return Value