Skip to content

Instantly share code, notes, and snippets.

@paulw11
Created January 8, 2020 05:15
Show Gist options
  • Save paulw11/baabe82e80f1392fea40c42bc7f1bfee to your computer and use it in GitHub Desktop.
Save paulw11/baabe82e80f1392fea40c42bc7f1bfee to your computer and use it in GitHub Desktop.
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