Latest 0.1.0
Homepage https://github.com/lucas34/SwiftQueue
License MIT
Platforms ios 8.0, requires ARC
Authors

Schedule tasks with constraints made easy.

Awesome
swift
travis
licence
pod
Carthage compatible
Platform
PRs Welcome
codecov
codebeat badge

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.

Features

  • [x] Sequential execution
  • [x] Concurrent run
  • [x] Persistence
  • [x] Cancel all or by tag
  • [x] Delay
  • [x] Deadline
  • [x] Internet constraint
  • [x] Single instance in queue
  • [x] Retry: Max count, exponential backoff
  • [x] Periodic: Max run, interval delay
  • [x] Start / Stop queue

Requirements

  • iOS 8.0+
  • Xcode 7.3

Installation

CocoaPods

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

platform :ios, '8.0'
use_frameworks!
pod 'SwiftQueue'

In your application, simply import the library

import SwiftQueue

Usage example

This short example will shows you how to schedule a task that send tweets. First, you will need to extend Job and implement 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 tweetMessage: String

    required init(message: String) {
        // Receive params from JobBuilder.with()
        self.tweetMessage = message
    }

    func onRun(callback: JobResult) throws {
        // Run your job here
        callback.onDone(error: nil)
    }

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

    func onRemove(error: Error?) {
        // This job will never run anymore  
        // Success if error is nil. fail otherwise
    }
}

The class SwiftQueueManager serves as entry point. Your jobs need to extend the class Job. Specify run and retry constraints with JobBuilder and schedule by giving SwiftQueueManager

let manager = SwiftQueueManager(creators: [TweetJobCreator()])

Schedule a job with type, parameters and constraints.

JobBuilder(type: SendTweetJob.type)
        // params of my job
        .with(params: "Hello TweetWorld")
        // Add to queue manager
        .schedule(manager: manager)

The JobCreator maps a job type to a specific job class. You will receive parameters you specified in JobBuilder.

class TweetJobCreator: JobCreator {

    // Base on type, return the actual job implementation
    func create(type: String, params: Any?) -> Job? {
        // check for job and params type
        if type == SendTweetJob.type, let message = params as? String  {
            return SendTweetJob(message: message)
        } else {
            // Nothing match
            return nil
        }
    }
}

That’s it. We haven’t specify any constraint so the job will run immediately. Check the WIKI for a more detailed example.

Contributors

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

Licence

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

Latest podspec

{
    "name": "SwiftQueue",
    "version": "0.1.0",
    "summary": "SwiftQueue",
    "description": "Job Scheduler for IOS with Concurrent run, failure/retry, persistence, repeat, delay and more",
    "homepage": "https://github.com/lucas34/SwiftQueue",
    "license": "MIT",
    "authors": {
        "Lucas Nelaupe": "lucas.nelaupe@gmail.com"
    },
    "source": {
        "git": "https://github.com/lucas34/SwiftQueue.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This