Swiftpack.co - Package - lucas34/SwiftQueue


Schedule tasks with constraints made easy.

Awesome platform swift travis codecov pod Carthage compatible Swift Package Manager compatible Documentation

SwiftQueue is a job scheduler for iOS inspired by popular android libraries like android-priority-jobqueue or android-job. It allows you to run your tasks with run and retry constraints.

Library will rely on Operation and OperationQueue to make sure all tasks will run in order. Don't forget to check our WIKI.


  • [x] Sequential or Concurrent execution
  • [x] Persistence
  • [x] Cancel all, by id or by tag
  • [x] Start / Stop queue

Job Constraints:

  • [x] Delay
  • [x] Deadline
  • [x] Timeout
  • [x] Internet
  • [x] Charging
  • [x] Single instance in queue
  • [x] Retry: Max count, exponential backoff
  • [x] Periodic: Max run, interval delay
  • [x] Experimental Foreground or Background execution


  • iOS 8.0+, watchOS 2.0+, macOS 10.10+, tvOS 9.0+
  • Xcode 13.0


SwiftPackageManager (SPM)

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/lucas34/SwiftQueue.git", .upToNextMajor(from: "4.0.0"))


SwiftQueue is carthage compatible. Add the following entry in your Cartfile:

github "lucas34/SwiftQueue"

Then run carthage update.


You can use CocoaPods to install SwiftQueue by adding it to your Podfile:

platform :ios, '8.0'
pod 'SwiftQueue'

In your application, simply import the library

import SwiftQueue


This example will simply wrap an api call. Create your custom job by extending Job with onRun, onRetry and onRemove callbacks.

// A job to send a tweet
class SendTweetJob: Job {
    // Type to know which Job to return in job creator
    static let type = "SendTweetJob"
    // Param
    private let tweet: [String: Any]

    required init(params: [String: Any]) {
        // Receive params from JobBuilder.with()
        self.tweet = params

    func onRun(callback: JobResult) {
        let api = Api()
        api.sendTweet(data: tweet).execute(onSuccess: {
        }, onError: { error in

    func onRetry(error: Error) -> RetryConstraint {
        // Check if error is non fatal
        return error is ApiError ? RetryConstraint.cancel : RetryConstraint.retry(delay: 0) // immediate retry

    func onRemove(result: JobCompletion) {
        // This job will never run anymore  
        switch result {
            case .success:
                // Job success
            case .fail(let error):
                // Job fail

Create your SwiftQueueManager and keep the reference. If you want to cancel a job it has to be done with the same instance.

let manager = SwiftQueueManagerBuilder(creator: TweetJobCreator()).build()

Schedule your job and specify the constraints.

JobBuilder(type: SendTweetJob.type)
        // Requires internet to run
        .internet(atLeast: .cellular)
        // params of my job
        .with(params: ["content": "Hello world"])
        // Add to queue manager
        .schedule(manager: manager)

Bind your job type with an actual instance.

class TweetJobCreator: JobCreator {

    // Base on type, return the actual job implementation
    func create(type: String, params: [String: Any]?) -> Job {
        // check for job and params type
        if type == SendTweetJob.type  {
            return SendTweetJob(params: params)
        } else {
            // Nothing match
            // You can use `fatalError` or create an empty job to report this issue.
            fatalError("No Job !")

3rd Party Extensions


We would love you for the contribution to SwiftQueue, check the LICENSE file for more info.


Distributed under the MIT license. See LICENSE for more information.


Stars: 182
Help us keep the lights on


Used By

Total: 1


4.0.1 - Oct 12, 2019

Bug Fix

  • Make all params in JobBuilder public (#266)

Breaking Changes

  • Remove Deprecated methods (#263)


Update dependencies (#262)

4.0.0 - Sep 21, 2019

Breaking Changes

  • Increased minimal support to 4.1 and XCode 11 (#248) (#246)

New features

  • Experimental support of BackgroundTask API (iOS/tvOS 13+) (#252) (#251) (#254) (#257)


  • Stop init variable at runtime (#258)
  • Avoid object creation (#250)
  • Cleanup (#247)

3.2.0 - Jun 9, 2019

New features

  • Job execution timeout constraint (#50)
  • Exponential backoff with max delay (#226)
  • Better threading configuration for Queue and Manager (#228) (#229) (#230)
  • Jobs can be enqueue from manager with .enqueue(JobInfo) (#231)

3.1.0 - May 13, 2019

New features

  • Job status listener (#217)
  • Allow a queue to run multiple jobs in parallel (#215)

Breaking changes

  • Rename synchronous to initInBackground (#213)
  • Rename group() to parallel() (#212)


  • Better control on running for duplicate job constraint (#219)
  • Add no logger by default (#211)

3.0.0 - Apr 4, 2019


  • Swift 5 support. Source was already compatible 🙌 (#206)
  • Drop Linux support (#206)