Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Job Scheduler for IOS with Concurrent run, failure/retry, persistence, repeat, delay and more

License

NotificationsYou must be signed in to change notification settings

lucas34/SwiftQueue

Repository files navigation

Schedule tasks with constraints made easy.

AwesomeplatformswiftSwiftcodecovpodCarthage compatibleSwift Package Manager compatibleDocumentation

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

Library will rely onOperation andOperationQueue to make sure all tasks will run in order. Don't forget to check ourWIKI.

Features

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

Job Constraints:

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

Requirements

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

Installation

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"))

Carthage

SwiftQueue iscarthage compatible. Add the following entry in yourCartfile:

github "lucas34/SwiftQueue"

Then runcarthage update.

CocoaPods

You can useCocoaPods to installSwiftQueue by adding it to yourPodfile:

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

In your application, simply import the library

import SwiftQueue

Example

This example will simply wrap an api call. Create your custom job by extendingJob withonRun,onRetry andonRemove callbacks.

// A job to send a tweetclassSendTweetJob:Job{        // Type to know which Job to return in job creatorstaticlettype="SendTweetJob"    // Paramprivatelettweet:[String:Any]requiredinit(params:[String:Any]){        // Receive params from JobBuilder.with()self.tweet= params}func onRun(callback:JobResult){letapi=Api()        api.sendTweet(data: tweet).execute(onSuccess:{            callback.done(.success)}, onError:{ errorin            callback.done(.fail(error))})}func onRetry(error:Error)->RetryConstraint{        // Check if error is non fatalreturn error isApiError?RetryConstraint.cancel:RetryConstraint.retry(delay:0) // immediate retry}func onRemove(result:JobCompletion){        // This job will never run anymoreswitch result{case.success:                // Job successbreakcase.fail(let error):                // Job failbreak}}}

Create yourSwiftQueueManager andkeep the reference. If you want to cancel a job it has to be done with the same instance.

letmanager=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 yourjob type with an actual instance.

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

3rd Party Extensions

Contributors

We would love you for the contribution toSwiftQueue, check theLICENSE file for more info.

License

Distributed under the MIT license. SeeLICENSE for more information.

About

Job Scheduler for IOS with Concurrent run, failure/retry, persistence, repeat, delay and more

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors14


[8]ページ先頭

©2009-2026 Movatter.jp