- Notifications
You must be signed in to change notification settings - Fork44
Job Scheduler for IOS with Concurrent run, failure/retry, persistence, repeat, delay and more
License
lucas34/SwiftQueue
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Schedule tasks with constraints made easy.
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.
- 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
- iOS 8.0+, watchOS 2.0+, macOS 10.10+, tvOS 9.0+
- Xcode 11.0
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 iscarthage compatible. Add the following entry in yourCartfile:
github "lucas34/SwiftQueue"Then runcarthage update.
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 SwiftQueueThis 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 !")}}}
- SQLitePersisterForSwiftQueue: A SQLite3 based persister for SwiftQueue
We would love you for the contribution toSwiftQueue, check theLICENSE file for more info.
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors14
Uh oh!
There was an error while loading.Please reload this page.