mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
fix remove job id concurrent issue
This commit is contained in:
parent
a856415438
commit
cebda588e8
|
@ -7,6 +7,8 @@ public final class JobQueue : NSObject, JobDelegate {
|
||||||
|
|
||||||
internal static var currentlyExecutingJobs: Set<String> = []
|
internal static var currentlyExecutingJobs: Set<String> = []
|
||||||
|
|
||||||
|
private let internalQueue: DispatchQueue = DispatchQueue(label:"executingJobQueue")
|
||||||
|
|
||||||
@objc public static let shared = JobQueue()
|
@objc public static let shared = JobQueue()
|
||||||
|
|
||||||
@objc public func add(_ job: Job, using transaction: Any) {
|
@objc public func add(_ job: Job, using transaction: Any) {
|
||||||
|
@ -47,7 +49,7 @@ public final class JobQueue : NSObject, JobDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func handleJobSucceeded(_ job: Job) {
|
public func handleJobSucceeded(_ job: Job) {
|
||||||
given(job.id) { JobQueue.currentlyExecutingJobs.remove($0) }
|
given(job.id) { removeExecutingJob($0) }
|
||||||
SNMessagingKitConfiguration.shared.storage.write(with: { transaction in
|
SNMessagingKitConfiguration.shared.storage.write(with: { transaction in
|
||||||
SNMessagingKitConfiguration.shared.storage.markJobAsSucceeded(job, using: transaction)
|
SNMessagingKitConfiguration.shared.storage.markJobAsSucceeded(job, using: transaction)
|
||||||
}, completion: {
|
}, completion: {
|
||||||
|
@ -56,7 +58,7 @@ public final class JobQueue : NSObject, JobDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func handleJobFailed(_ job: Job, with error: Error) {
|
public func handleJobFailed(_ job: Job, with error: Error) {
|
||||||
given(job.id) { JobQueue.currentlyExecutingJobs.remove($0) }
|
given(job.id) { removeExecutingJob($0) }
|
||||||
job.failureCount += 1
|
job.failureCount += 1
|
||||||
let storage = SNMessagingKitConfiguration.shared.storage
|
let storage = SNMessagingKitConfiguration.shared.storage
|
||||||
guard !storage.isJobCanceled(job) else { return SNLog("\(type(of: job)) canceled.") }
|
guard !storage.isJobCanceled(job) else { return SNLog("\(type(of: job)) canceled.") }
|
||||||
|
@ -78,7 +80,7 @@ public final class JobQueue : NSObject, JobDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func handleJobFailedPermanently(_ job: Job, with error: Error) {
|
public func handleJobFailedPermanently(_ job: Job, with error: Error) {
|
||||||
given(job.id) { JobQueue.currentlyExecutingJobs.remove($0) }
|
given(job.id) { removeExecutingJob($0) }
|
||||||
job.failureCount += 1
|
job.failureCount += 1
|
||||||
let storage = SNMessagingKitConfiguration.shared.storage
|
let storage = SNMessagingKitConfiguration.shared.storage
|
||||||
storage.write(with: { transaction in
|
storage.write(with: { transaction in
|
||||||
|
@ -92,6 +94,10 @@ public final class JobQueue : NSObject, JobDelegate {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func removeExecutingJob(_ jobID: String) {
|
||||||
|
let _ = internalQueue.sync { JobQueue.currentlyExecutingJobs.remove(jobID) }
|
||||||
|
}
|
||||||
|
|
||||||
private func getRetryInterval(for job: Job) -> TimeInterval {
|
private func getRetryInterval(for job: Job) -> TimeInterval {
|
||||||
// Arbitrary backoff factor...
|
// Arbitrary backoff factor...
|
||||||
// try 1 delay: 0.5s
|
// try 1 delay: 0.5s
|
||||||
|
|
Loading…
Reference in a new issue