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
retryStrategyis nil, in which case failed jobs are simply removed from the queue.Declaration
Swift
public var retryStrategy: JobRetryStrategy? -
Returns the current
JobQueue.Stateof this instanceDeclaration
Swift
private(set) public var state: State -
Gets the
JobProcessorto process the jobs on this instance, if any; otherwisenil.JobQueues without aJobProcessormust manually process and remove jobs from the queue.Declaration
Swift
public var processor: AnyJobProcessor<Job>? -
Gets the
JobPersisterto persist jobs in this queue, if one exists; otherwise nil. JobQueues that do not have aJobPersisterwill 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) throwsParameters
handlingThe expect type of QueueJob this JobQueue will handle
nameThe name for this queue.
persisterA JobPersister that may be used to persist jobs.
-
Returns the number of jobs in this
JobQueueawaiting processing.Declaration
Swift
public var count: Int -
Adds the provided
jobsto thisJobQueue, while maintaining their order.Remark
This function is thread safe.Declaration
Swift
public func add(_ jobs: [Job])Parameters
jobsThe jobs to be added to this
JobQueue. -
Queues the provided
jobfor immediate processing. That is, the provided job will be inserted at the very front of thisJobQueueRemark
This function is thread safeDeclaration
Swift
public func retry(_ job: Job)Parameters
jobThe job to be inserted at the front of this
JobQueue -
Attempts to return without removing the next
Jobat the front of thisJobQueue.Remark
This function is thread safeDeclaration
Swift
public func peek() -> Job?Return Value
The next
Jobat the front of thisJobQueue, if one exists; otherwise nil -
Removes the next
Jobfrom the front of thisJobQueueRemark
This function is thread safeDeclaration
Swift
public func remove() -> Job?Return Value
The next
Jobat the front of thisJobQueue, if one exists; otherwise nil -
Cancels the job in this
JobQueuewith the providedid, if it exists.Attention
This cannot cancel a matchingJobif thatJobis already being processed.Remark
This function is thread safeDeclaration
Swift
public func cancel(_ id: String)Parameters
idThe
idof theJobto be removed from thisJobQueue -
Removes all jobs from this JobQueue
Remark
This function is thread safeDeclaration
Swift
public func drain()
-
Tells this
JobQueueto start processing itsJobsDeclaration
Swift
public func start() -
Tells this
JobQueueto stop processing itsJobs.Declaration
Swift
public func stop()
-
Subscribes a listener to this
JobQueue.Attention
The returned
JobQueueNotificationTokenisweak, 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
blockThe function to be called which will receive the notification
queueThe
JobQueuefrom which the notification is broadcastjobsThe jobs affected by the
JobQueueEventeventThe
JobQueueEvent(such as.added,.removed, etc) affecting the providedjobsReturn Value
View on GitHub
JobQueue Class Reference