JobKit
Warning: this project is in alpha state
About
JobKit is a job queueing system for iOS application. It has a pluggable storage adapters and this repo contains adapters for Core Data (persistent), Realm (persistent) and a memory adapter.
Currently it has a naive implementation for a mobile device as it checks periodically (tickInterval) for new jobs but I'm going to implement an notifications based processing trigger.
Installation
JobKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
# this will install all the available storage adapters and their dependencies
pod "JobKit"
# this will install the core classes and the Realm adapter
pod "JobKit/Realm"
# this will install the core classes and the Core Data adapter
pod "JobKit/CoreData"
# this will install the core classes and the Memory adapter
pod "JobKit/Memory"Usage
In your AppDelegate initialize JobKit:
//initialize manager
[JobKit setupDefaultManagerWithStorageProvider:[JKCoreDataAdapter class]];
//set tick interval
[JobKit defaultManager].tickInterval = .5;
//start processing jobs
[JobKit start];There are 3 way in which you can enqueue jobs to JobKit:
1 - Creating a subclass of JKJob
@interface JKTestJob : JKJob
@end
@implementation JKTestJob
- (void)perform {
//any arguments passed to the job can be found at self.arguments
}
@end
//enqueue a job
[JKTestJob performLater:nil];
[JKTestJob performLater:@["arg"]];
[JKTestJob performLater:@[@"arg1", @"2", @{@(3) : @"4"}]];Important: All arguments must conform to the NSCoding protocol.
2 - Enqueue invocation of a class method for any object
@interface SomeClass : NSObject
+ (void)aClassMethod;
+ (void)aClassMethodWithAnArgument:(id)arg1 andAnother:(id)arg2;
@end
[SomeClass jk_performLater:@selector(aClassMethod) arguments:nil]
[SomeClass jk_performLater:@selector(aClassMethodWithAnArgument:andAnother:) arguments:@["arg", @(2)]]Important: All arguments must conform to the NSCoding protocol.
3 - Enqueue invocation of an instance method for any object instance
@interface SomeClass : NSObject
- (void)aClassMethod;
- (void)aClassMethodWithAnArgument:(id)arg1 andAnother:(id)arg2;
@end
[[SomeClass new] jk_performLater:@selector(aClassMethod) arguments:nil]
[[SomeClass new] jk_performLater:@selector(aClassMethodWithAnArgument:andAnother:) arguments:@["arg", @(2)]]Important: The object and all arguments must conform to the NSCoding protocol.
TODO
- Optimize triggering job processing
- Implement retry mechanism
- Query interface for jobs
- UI for jobs
- Schedule jobs in the future / with delay
- Process jobs on background modes
Author
Cristian Bica, cristian.bica@gmail.com
License
JobKit is available under the MIT license. See the LICENSE file for more info.