Skip to content
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
3 changes: 2 additions & 1 deletion EDQueue.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Pod::Spec.new do |s|
s.homepage = 'https://github.com/thisandagain/queue'
s.authors = {'Andrew Sliwinski' => '[email protected]', 'Francois Lambert' => '[email protected]'}
s.source = { :git => 'https://github.com/thisandagain/queue.git', :tag => 'v0.7.1' }
s.platform = :ios, '5.0'
s.ios.platform = :ios, '5.0'
s.osx.platform = :osx, '10.8'
s.source_files = 'EDQueue'
s.library = 'sqlite3.0'
s.requires_arc = true
Expand Down
5 changes: 4 additions & 1 deletion EDQueue/EDQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2012 Andrew Sliwinski. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, EDQueueResult) {
EDQueueResultSuccess = 0,
Expand Down Expand Up @@ -42,6 +42,9 @@ extern NSString *const EDQueueDidDrain;
- (BOOL)jobIsActiveForTask:(NSString *)task;
- (NSDictionary *)nextJobForTask:(NSString *)task;

- (NSUInteger)jobCountForTask:(NSString *)task;
- (NSUInteger)totalJobCount;

@end

@protocol EDQueueDelegate <NSObject>
Expand Down
22 changes: 22 additions & 0 deletions EDQueue/EDQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ - (NSDictionary *)nextJobForTask:(NSString *)task
return nextJobForTask;
}

/**
* Returns the number of jobs for task
*
* @param {NSString} Task label
*
* @return {NSUinteger}
*/
- (NSUInteger)jobCountForTask:(NSString *)task
{
return [self.engine jobCountForTask:task];
}

/**
* Returns the total number of jobs
*
* @return {NSUinteger}
*/
- (NSUInteger)totalJobCount
{
return [self.engine fetchJobCount];
}

/**
* Starts the queue.
*
Expand Down
1 change: 1 addition & 0 deletions EDQueue/EDQueueStorageEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- (void)removeJob:(NSNumber *)jid;
- (void)removeAllJobs;
- (NSUInteger)fetchJobCount;
- (NSUInteger)jobCountForTask:(id)task;
- (NSDictionary *)fetchJob;
- (NSDictionary *)fetchJobForTask:(id)task;

Expand Down
23 changes: 17 additions & 6 deletions EDQueue/EDQueueStorageEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ - (id)init
self = [super init];
if (self) {
// Database path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"edqueue_0.5.0d.db"];

Expand Down Expand Up @@ -71,22 +71,33 @@ - (void)createJob:(id)data forTask:(id)task
*/
- (BOOL)jobExistsForTask:(id)task
{
__block BOOL jobExists = NO;

return [self jobCountForTask:task] > 0;
}

/**
+ * Returns the number of jobs for the specified task name.
+ *
+ * @param {NSString} Task name
+ *
+ * @return {NSUinteger}
+ */
- (NSUInteger)jobCountForTask:(id)task
{
__block NSUInteger jobCount = 0;
[self.queue inDatabase:^(FMDatabase *db) {
FMResultSet *rs = [db executeQuery:@"SELECT count(id) AS count FROM queue WHERE task = ?", task];
[self _databaseHadError:[db hadError] fromDatabase:db];

while ([rs next]) {
jobExists |= ([rs intForColumn:@"count"] > 0);
jobCount = [rs intForColumn:@"count"];
}

[rs close];
}];

return jobExists;
return jobCount;
}


/**
* Increments the "attempts" column for a specified job.
*
Expand Down
Loading