mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
Swift
61 lines
2.0 KiB
Swift
3 years ago
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
2 years ago
|
import Combine
|
||
3 years ago
|
import GRDB
|
||
2 years ago
|
import SignalCoreKit
|
||
3 years ago
|
import SessionUtilitiesKit
|
||
|
|
||
|
public enum GetSnodePoolJob: JobExecutor {
|
||
|
public static let maxFailureCount: Int = -1
|
||
|
public static let requiresThreadId: Bool = false
|
||
|
public static let requiresInteractionId: Bool = false
|
||
|
|
||
|
public static func run(
|
||
|
_ job: Job,
|
||
3 years ago
|
queue: DispatchQueue,
|
||
3 years ago
|
success: @escaping (Job, Bool) -> (),
|
||
|
failure: @escaping (Job, Error?, Bool) -> (),
|
||
|
deferred: @escaping (Job) -> ()
|
||
|
) {
|
||
3 years ago
|
// If the user doesn't exist then don't do anything (when the user registers we run this
|
||
|
// job directly)
|
||
|
guard Identity.userExists() else {
|
||
|
deferred(job)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// If we already have cached Snodes then we still want to trigger the 'SnodeAPI.getSnodePool'
|
||
|
// but we want to succeed this job immediately (since it's marked as blocking), this allows us
|
||
|
// to block if we have no Snode pool and prevent other jobs from failing but avoids having to
|
||
|
// wait if we already have a potentially valid snode pool
|
||
|
guard !SnodeAPI.hasCachedSnodesInclusingExpired() else {
|
||
2 years ago
|
SnodeAPI.getSnodePool().sinkUntilComplete()
|
||
3 years ago
|
success(job, false)
|
||
|
return
|
||
|
}
|
||
|
|
||
3 years ago
|
SnodeAPI.getSnodePool()
|
||
2 years ago
|
.subscribe(on: queue)
|
||
|
.receive(on: queue)
|
||
|
.sinkUntilComplete(
|
||
|
receiveCompletion: { result in
|
||
|
switch result {
|
||
|
case .finished: success(job, false)
|
||
|
case .failure(let error): failure(job, error, false)
|
||
|
}
|
||
|
}
|
||
|
)
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
public static func run() {
|
||
|
GetSnodePoolJob.run(
|
||
|
Job(variant: .getSnodePool),
|
||
3 years ago
|
queue: DispatchQueue.global(qos: .background),
|
||
3 years ago
|
success: { _, _ in },
|
||
|
failure: { _, _, _ in },
|
||
|
deferred: { _ in }
|
||
|
)
|
||
|
}
|
||
3 years ago
|
}
|