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.
session-ios/SignalUtilitiesKit/Database/Storage/Storage+Jobs.swift

41 lines
1.6 KiB
Swift

extension Storage {
public func persist(_ job: Job, using transaction: Any) {
(transaction as! YapDatabaseReadWriteTransaction).setObject(job, forKey: job.id!, inCollection: type(of: job).collection)
}
public func markJobAsSucceeded(_ job: Job, using transaction: Any) {
(transaction as! YapDatabaseReadWriteTransaction).removeObject(forKey: job.id!, inCollection: type(of: job).collection)
}
public func markJobAsFailed(_ job: Job, using transaction: Any) {
(transaction as! YapDatabaseReadWriteTransaction).removeObject(forKey: job.id!, inCollection: type(of: job).collection)
}
public func getAllPendingJobs(of type: Job.Type) -> [Job] {
var result: [Job] = []
Storage.read { transaction in
transaction.enumerateRows(inCollection: type.collection) { _, object, _, _ in
guard let job = object as? Job else { return }
result.append(job)
}
}
return result
}
public func getAttachmentUploadJob(for attachmentID: String) -> AttachmentUploadJob? {
var result: [AttachmentUploadJob] = []
Storage.read { transaction in
transaction.enumerateRows(inCollection: AttachmentUploadJob.collection) { _, object, _, _ in
guard let job = object as? AttachmentUploadJob, job.attachmentID == attachmentID else { return }
result.append(job)
}
}
#if DEBUG
assert(result.isEmpty || result.count == 1)
#endif
return result.first
}
}