Created
January 8, 2020 05:15
-
-
Save paulw11/baabe82e80f1392fea40c42bc7f1bfee to your computer and use it in GitHub Desktop.
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 BackgroundJobCreator: JobCreator { | |
func create(type: String, params: [String : Any]?)->Job { | |
return SendTweetJob(params:[:]) | |
} | |
} | |
class SendTweetJob: Job { | |
// Type to know which Job to return in job creator | |
static let type = "SendTweetJob" | |
// Param | |
private let tweet: [String: Any] | |
required init(params: [String: Any]) { | |
// Receive params from JobBuilder.with() | |
self.tweet = params | |
} | |
func onRun(callback: JobResult) { | |
callback.done(.success) | |
} | |
func onRetry(error: Error) -> RetryConstraint { | |
// Check if error is non fatal | |
return RetryConstraint.cancel | |
} | |
func onRemove(result: JobCompletion) { | |
// This job will never run anymore | |
switch result { | |
case .success: | |
// Job success | |
break | |
case .fail(let error): | |
// Job fail | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment