Skip to content

Instantly share code, notes, and snippets.

@mwrites
Created September 14, 2017 11:25
Show Gist options
  • Save mwrites/2e6b267c7a8f2089d0e2febf087e45ee to your computer and use it in GitHub Desktop.
Save mwrites/2e6b267c7a8f2089d0e2febf087e45ee to your computer and use it in GitHub Desktop.
JobQueueCenter DocumentUploadServiceJob
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