Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jacobsapps/f352d3e08f768681d23e5c5cf898042b to your computer and use it in GitHub Desktop.

Select an option

Save jacobsapps/f352d3e08f768681d23e5c5cf898042b to your computer and use it in GitHub Desktop.
private func processQueueIfNeeded() async {
guard !isProcessing else { return }
isProcessing = true
defer { isProcessing = false }
while let nextJob = fetchNextOutstandingJobSnapshot() {
do {
try withJob(nextJob.id) { _, job in
job.state = .uploading
job.attempts += 1
job.lastError = nil
job.updatedAt = .now
}
try await submitLevel4Tweet(text: nextJob.text)
try withJob(nextJob.id) { context, job in context.delete(job) }
} catch {
try? withJob(nextJob.id) { _, job in
job.state = .failed
job.lastError = error.localizedDescription
job.updatedAt = .now
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment