All Projects → thisandagain → Queue

thisandagain / Queue

Licence: mit
A persistent background job queue for iOS.

Labels

Projects that are alternatives of or similar to Queue

queue-promise
A simple, dependency-free library for concurrent promise-based queues. Comes with with concurrency and timeout control.
Stars: ✭ 56 (-79.41%)
Mutual labels:  queue
Tesseract
A set of libraries for rapidly developing Pipeline driven micro/macroservices.
Stars: ✭ 20 (-92.65%)
Mutual labels:  queue
yerbie
A blazing fast job queue built for ease of use and scalability
Stars: ✭ 16 (-94.12%)
Mutual labels:  queue
Data-Structures-and-Algorithms
Implementation of various Data Structures and algorithms - Linked List, Stacks, Queues, Binary Search Tree, AVL tree,Red Black Trees, Trie, Graph Algorithms, Sorting Algorithms, Greedy Algorithms, Dynamic Programming, Segment Trees etc.
Stars: ✭ 144 (-47.06%)
Mutual labels:  queue
linda
Linda is a simple dispatcher library.
Stars: ✭ 12 (-95.59%)
Mutual labels:  queue
Data-Structures-and-Algorithms
Data Structures and Algorithms implementation in Python
Stars: ✭ 31 (-88.6%)
Mutual labels:  queue
psched
Priority-based Task Scheduling for Modern C++
Stars: ✭ 59 (-78.31%)
Mutual labels:  queue
Gostl
Data structure and algorithm library for go, designed to provide functions similar to C++ STL
Stars: ✭ 254 (-6.62%)
Mutual labels:  queue
rust-sidekiq
Rust Sidekiq Client
Stars: ✭ 24 (-91.18%)
Mutual labels:  queue
goqueue
See https://github.com/damnever/goctl
Stars: ✭ 48 (-82.35%)
Mutual labels:  queue
celery.node
Celery task queue client/worker for nodejs
Stars: ✭ 164 (-39.71%)
Mutual labels:  queue
getui
Getui sdk package for laravel.
Stars: ✭ 19 (-93.01%)
Mutual labels:  queue
Data-structures
Data Structures in Java
Stars: ✭ 13 (-95.22%)
Mutual labels:  queue
mongo
Light-weight utilities and declarative schema (mutable mapping) to augment, not replace the Python MongoDB driver.
Stars: ✭ 18 (-93.38%)
Mutual labels:  queue
horizon-exporter
Export Laravel Horizon metrics using this Prometheus exporter.
Stars: ✭ 17 (-93.75%)
Mutual labels:  queue
DSA
Data Structures and Algorithms
Stars: ✭ 13 (-95.22%)
Mutual labels:  queue
elixir-queue
Queue data structure for Elixir-lang
Stars: ✭ 18 (-93.38%)
Mutual labels:  queue
Javascript Datastructures Algorithms
📚 collection of JavaScript and TypeScript data structures and algorithms for education purposes. Source code bundle of JavaScript algorithms and data structures book
Stars: ✭ 3,221 (+1084.19%)
Mutual labels:  queue
queue-promises
Promises for Laravel queue jobs
Stars: ✭ 15 (-94.49%)
Mutual labels:  queue
yii2-queuemanager
Yii2 Queue Manager (Analytic & Monitor)
Stars: ✭ 18 (-93.38%)
Mutual labels:  queue

Queue

A persistent background job queue for iOS.

While NSOperation and NSOperationQueue work well for some repetitive problems and NSInvocation for others, iOS doesn't really include a set of tools for managing large collections of arbitrary background tasks easily. EDQueue provides a high-level interface for implementing a threaded job queue using GCD and SQLLite3. All you need to do is handle the jobs within the provided delegate method and EDQueue handles the rest.

Getting Started

The easiest way to get going with EDQueue is to take a look at the included example application. The Xcode project file can be found in Project > queue.xcodeproj.

Setup

EDQueue needs both libsqlite3.0.dylib and FMDB for the storage engine. As always, the quickest way to take care of all those details is to use CocoaPods. EDQueue is implemented as a singleton as to allow jobs to be created from anywhere throughout an application. However, tasks are all processed through a single delegate method and thus it often makes the most sense to setup EDQueue within the application delegate:

YourAppDelegate.h

#import "EDQueue.h"
@interface YourAppDelegate : UIResponder <UIApplicationDelegate, EDQueueDelegate>

YourAppDelegate.m

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[EDQueue sharedInstance] setDelegate:self];
    [[EDQueue sharedInstance] start];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    [[EDQueue sharedInstance] stop];
}

- (EDQueueResult)queue:(EDQueue *)queue processJob:(NSDictionary *)job
{
    sleep(1);           // This won't block the main thread. Yay!
    
    // Wrap your job processing in a try-catch. Always use protection!
    @try {
        if ([[job objectForKey:@"task"] isEqualToString:@"success"]) {
            return EDQueueResultSuccess;
        } else if ([[job objectForKey:@"task"] isEqualToString:@"fail"]) {
            return EDQueueResultFail;
        }
    }
    @catch (NSException *exception) {
        return EDQueueResultCritical;
    }
    
    return EDQueueResultCritical;
}

SomewhereElse.m

[[EDQueue sharedInstance] enqueueWithData:@{ @"foo" : @"bar" } forTask:@"nyancat"];

In order to keep things simple, the delegate method expects a return type of EDQueueResult which permits three distinct states:

  • EDQueueResultSuccess: Used to indicate that a job has completed successfully
  • EDQueueResultFail: Used to indicate that a job has failed and should be retried (up to the specified retryLimit)
  • EDQueueResultCritical: Used to indicate that a job has failed critically and should not be attempted again

Handling Async Jobs

As of v0.6.0 queue includes a delegate method suited for handling asyncronous jobs such as HTTP requests or Disk I/O:

- (void)queue:(EDQueue *)queue processJob:(NSDictionary *)job completion:(void (^)(EDQueueResult))block
{
    sleep(1);
    
    @try {
        if ([[job objectForKey:@"task"] isEqualToString:@"success"]) {
            block(EDQueueResultSuccess);
        } else if ([[job objectForKey:@"task"] isEqualToString:@"fail"]) {
            block(EDQueueResultFail);
        } else {
            block(EDQueueResultCritical);
        }
    }
    @catch (NSException *exception) {
        block(EDQueueResultCritical);
    }
}

Introspection

As of v0.7.0 queue includes a collection of methods to aid in queue introspection specific to each task:

- (Boolean)jobExistsForTask:(NSString *)task;
- (Boolean)jobIsActiveForTask:(NSString *)task;
- (NSDictionary *)nextJobForTask:(NSString *)task;

Methods

- (void)enqueueWithData:(id)data forTask:(NSString *)task;

- (void)start;
- (void)stop;
- (void)empty;

- (Boolean)jobExistsForTask:(NSString *)task;
- (Boolean)jobIsActiveForTask:(NSString *)task;
- (NSDictionary *)nextJobForTask:(NSString *)task;

Delegate Methods

- (EDQueueResult)queue:(EDQueue *)queue processJob:(NSDictionary *)job;
- (void)queue:(EDQueue *)queue processJob:(NSDictionary *)job completion:(void (^)(EDQueueResult result))block;

Result Types

EDQueueResultSuccess
EDQueueResultFail
EDQueueResultCritical

Properties

@property (weak) id<EDQueueDelegate> delegate;
@property (readonly) Boolean isRunning;
@property (readonly) Boolean isActive;
@property NSUInteger retryLimit;

Notifications

EDQueueDidStart
EDQueueDidStop
EDQueueDidDrain
EDQueueJobDidSucceed
EDQueueJobDidFail

iOS Support

EDQueue is designed for iOS 5 and up.

ARC

EDQueue is built using ARC. If you are including EDQueue in a project that does not use Automatic Reference Counting (ARC), you will need to set the -fobjc-arc compiler flag on all of the EDQueue source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. Now select all EDQueue source files, press Enter, insert -fobjc-arc and then "Done" to enable ARC for EDQueue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].