Created
September 14, 2017 11:25
-
-
Save mwrites/2e6b267c7a8f2089d0e2febf087e45ee to your computer and use it in GitHub Desktop.
JobQueueCenter DocumentUploadServiceJob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DocumentUploadService : NSObject, Job { | |
//MARK: - | |
//MARK: Logic | |
var document: Data | |
init(document: Data) { ... } | |
func execute(complete: @escaping (Bool)->Void) { ... } | |
//MARK: - | |
//MARK: Job | |
var retryableCount: Int = 3 | |
required convenience init?(coder aDecoder: NSCoder) { | |
guard let document = aDecoder.decodeObject(forKey: "document") as? Data else { return nil } | |
let retryableCount = aDecoder.decodeInteger(forKey: "retryableCount") | |
self.init(document: document) | |
self.retryableCount = retryableCount | |
} | |
func encode(with aCoder: NSCoder) { | |
aCoder.encode(document, forKey: "document") | |
aCoder.encode(retryableCount, forKey: "retryableCount") | |
} | |
func run() { | |
retryableCount = retryableCount - 1 | |
execute { | |
//if the job suceedeed there is nothing left to do. | |
guard $0 == false else { return } | |
NotificationCenter.default.post(name: Notification.Name.JobFailedNotification, object: self) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment