-
Notifications
You must be signed in to change notification settings - Fork 0
ZLManager
###Overview
ZLManager is a class for managing TaskWorkers. You should subclass this and override the required methods. A ZLManager subclass can be responsible for one or more TaskWorkers. It is responsible for creating these TaskWorkers when the TaskManager asks for them. The TaskManager will ask your subclass to create a TaskWorker when it is ready to start a task that has the same task type that your instance registered for with the TaskManager for more details go to the TaskManager page. It is also required that you call setupWithWorkItem: on the TaskWorker you create with workItem as the parameter. This initializes the TaskWorker with all the information it needs.
##Usage
###Methods to override
####Creating task workers
You must override the taskWorkerForWorkItem: method. This method is called by the TaskManager when it needs a TaskWorker for a Task you queued with the task type you registered the Manager for. Example:
- (ZLTaskWorker *)taskWorkerForWorkItem:(ZLInternalWorkItem *)workItem
{
//This should be defined as a constant somewhere
NSString *taskType = @"test.task.type";
ZLTaskWorker *taskWorker;
if ([workItem.taskType isEqualToString:taskType]) {
taskWorker = [ZLTaskWorkerSubclass new];
} else if ([workItem.taskType isEqualToString:@"otherTaskTypeManagerHandles"]) {
taskWorker = [ZLOtherTaskWorkerSubclass new];
} else
// If your Manager is registered for a task type you MUST handle it. This line of code should never execute
// if you are implementing this correctly. It is recommended to log here in case this happens so you
// know what's going wrong.
NSLog(@"Manager is not handling task type %@", workItem.taskType);
}
// Required
[taskWorker setupWithWorkItem:workItem];
return taskWorker;
}####Handling failure.
When a TaskWorker fails, it will retry a certain number of times; however, eventually it will stop retrying (even if it is set up to retry forever it only tries so many times in a session). If it failed on the last retry the workItemDidFail method is called on the ZLManager that is responsible for it.
You are not required to override to override this method. It is here for you if you want to implement custom behavior when if the TaskWorker has failed out. Example:
- (void)workItemDidFail:(ZLInternalWorkItem *)workItem
{
NSLog(@"A task failed with taskType %@", workItem.taskType);
}