Skip to content

Added initWithPath: to better facilitate multiple queues. #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions EDQueue/EDQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern NSString *const EDQueueDidDrain;
@interface EDQueue : NSObject

+ (EDQueue *)sharedInstance;
+ (NSString *)defaultPath;
- (id)initWithPath:(NSString *)path;

@property (nonatomic, weak) id<EDQueueDelegate> delegate;

Expand Down
15 changes: 13 additions & 2 deletions EDQueue/EDQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ @implementation EDQueue

#pragma mark - Singleton

+ (NSString *)defaultPath
{
return @"edqueue_0.5.0d.db";
}

+ (EDQueue *)sharedInstance
{
static EDQueue *singleton = nil;
Expand All @@ -49,11 +54,17 @@ + (EDQueue *)sharedInstance

#pragma mark - Init

- (id)init
- (id)init {
self = [self initWithPath:[self.class defaultPath]];
return self;
}

- (id)initWithPath:(NSString *)path
{
NSAssert(path != nil, @"Path is required and may not be null");
self = [super init];
if (self) {
_engine = [[EDQueueStorageEngine alloc] init];
_engine = [[EDQueueStorageEngine alloc] initWithPath:path];
_retryLimit = 4;
}
return self;
Expand Down
1 change: 1 addition & 0 deletions EDQueue/EDQueueStorageEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@property (retain) FMDatabaseQueue *queue;

- (id)initWithPath:(NSString *)inputPath;
- (void)createJob:(id)data forTask:(id)task;
- (BOOL)jobExistsForTask:(id)task;
- (void)incrementAttemptForJob:(NSNumber *)jid;
Expand Down
4 changes: 2 additions & 2 deletions EDQueue/EDQueueStorageEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ @implementation EDQueueStorageEngine

#pragma mark - Init

- (id)init
- (id)initWithPath:(NSString *)inputPath
{
self = [super init];
if (self) {
// Database path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"edqueue_0.5.0d.db"];
NSString *path = [documentsDirectory stringByAppendingPathComponent:inputPath];

// Allocate the queue
_queue = [[FMDatabaseQueue alloc] initWithPath:path];
Expand Down