diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index efbc555..59452eb 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -16,7 +16,8 @@ jobs: dbimage: - mongo runner: - - swift:5.8-focal + - swift:5.9-focal + - swift:5.10-focal - swiftlang/swift:nightly-main-focal container: ${{ matrix.runner }} runs-on: ubuntu-latest diff --git a/Package.resolved b/Package.resolved index 7b7a064..ef49bb9 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,88 +1,113 @@ { - "object": { - "pins": [ - { - "package": "BSON", - "repositoryURL": "https://github.com/orlandos-nl/BSON.git", - "state": { - "branch": null, - "revision": "6056eae6adbc268963217a6c95a32a4dc4ee6884", - "version": "8.0.9" - } - }, - { - "package": "DNSClient", - "repositoryURL": "https://github.com/orlandos-nl/DNSClient.git", - "state": { - "branch": null, - "revision": "770249dcb7259c486f2d68c164091b115ccb765f", - "version": "2.2.1" - } - }, - { - "package": "MongoKitten", - "repositoryURL": "https://github.com/orlandos-nl/MongoKitten.git", - "state": { - "branch": null, - "revision": "34929f3126017edb1e29cfc16fb19881189cf58d", - "version": "7.7.1" - } - }, - { - "package": "swift-atomics", - "repositoryURL": "https://github.com/apple/swift-atomics.git", - "state": { - "branch": null, - "revision": "6c89474e62719ddcc1e9614989fff2f68208fe10", - "version": "1.1.0" - } - }, - { - "package": "swift-collections", - "repositoryURL": "https://github.com/apple/swift-collections.git", - "state": { - "branch": null, - "revision": "937e904258d22af6e447a0b72c0bc67583ef64a2", - "version": "1.0.4" - } - }, - { - "package": "swift-log", - "repositoryURL": "https://github.com/apple/swift-log.git", - "state": { - "branch": null, - "revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7", - "version": "1.4.2" - } - }, - { - "package": "swift-metrics", - "repositoryURL": "https://github.com/apple/swift-metrics.git", - "state": { - "branch": null, - "revision": "eadb828f878fed144387e3845866225bb7082c56", - "version": "2.3.0" - } - }, - { - "package": "swift-nio", - "repositoryURL": "https://github.com/apple/swift-nio.git", - "state": { - "branch": null, - "revision": "cf281631ff10ec6111f2761052aa81896a83a007", - "version": "2.58.0" - } - }, - { - "package": "swift-nio-ssl", - "repositoryURL": "https://github.com/apple/swift-nio-ssl.git", - "state": { - "branch": null, - "revision": "52a486ff6de9bc3e26bf634c5413c41c5fa89ca5", - "version": "2.17.2" - } + "pins" : [ + { + "identity" : "bson", + "kind" : "remoteSourceControl", + "location" : "https://github.com/orlandos-nl/BSON.git", + "state" : { + "revision" : "944dfb3b0eb028f477c25ba6a071181de8ab903a", + "version" : "8.0.10" } - ] - }, - "version": 1 + }, + { + "identity" : "dnsclient", + "kind" : "remoteSourceControl", + "location" : "https://github.com/orlandos-nl/DNSClient.git", + "state" : { + "revision" : "770249dcb7259c486f2d68c164091b115ccb765f", + "version" : "2.2.1" + } + }, + { + "identity" : "mongokitten", + "kind" : "remoteSourceControl", + "location" : "https://github.com/orlandos-nl/MongoKitten.git", + "state" : { + "revision" : "929e88ff318a56c8113c692c47f7aed11cc85b0c", + "version" : "7.9.0" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "cd142fd2f64be2100422d658e7411e39489da985", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb", + "version" : "1.1.0" + } + }, + { + "identity" : "swift-distributed-tracing", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-distributed-tracing.git", + "state" : { + "revision" : "7fbb8b23b77ee548b3d0686b6faf735c1b3c7cb8", + "version" : "1.1.0" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", + "version" : "1.5.4" + } + }, + { + "identity" : "swift-metrics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-metrics.git", + "state" : { + "revision" : "971ba26378ab69c43737ee7ba967a896cb74c0d1", + "version" : "2.4.1" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982", + "version" : "2.64.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5", + "version" : "2.26.0" + } + }, + { + "identity" : "swift-service-context", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-service-context.git", + "state" : { + "revision" : "ce0141c8f123132dbd02fd45fea448018762df1b", + "version" : "1.0.0" + } + }, + { + "identity" : "swift-system", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-system.git", + "state" : { + "revision" : "025bcb1165deab2e20d4eaba79967ce73013f496", + "version" : "1.2.1" + } + } + ], + "version" : 2 } diff --git a/Package.swift b/Package.swift index 235f2e2..554c1b7 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.8 +// swift-tools-version:5.9 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -17,7 +17,7 @@ let package = Package( ], dependencies: [ // Dependencies declare other packages that this package depends on. - .package(url: "https://github.com/orlandos-nl/MongoKitten.git", from: "7.8.0"), + .package(url: "https://github.com/orlandos-nl/MongoKitten.git", from: "7.9.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/Sources/MongoQueue/MongoQueue.swift b/Sources/MongoQueue/MongoQueue.swift index 5f5d4a0..e747b5e 100644 --- a/Sources/MongoQueue/MongoQueue.swift +++ b/Sources/MongoQueue/MongoQueue.swift @@ -1,5 +1,6 @@ import Logging import MongoCore +import NIOConcurrencyHelpers import Foundation import Meow @@ -24,7 +25,7 @@ import Meow /// ```swift /// try await queue.queueTask(Reminder(username: "Joannis")) /// ``` -public final class MongoQueue { +public final class MongoQueue: @unchecked Sendable { public struct Option: Hashable { internal enum _Option: Hashable { case uniqueKeysEnabled @@ -38,10 +39,18 @@ public final class MongoQueue { internal let collection: MongoCollection internal let logger = Logger(label: "org.openkitten.mongo-queues") private var knownTypes = [KnownType]() - private var started = false - private var serverHasData = true + private let _started = NIOLockedValueBox(false) + private var started: Bool { + get { _started.withLockedValue { $0 } } + set { _started.withLockedValue { $0 = newValue } } + } + private let _serverHasData = NIOLockedValueBox(true) + private var serverHasData: Bool { + get { _serverHasData.withLockedValue { $0 } } + set { _serverHasData.withLockedValue { $0 = newValue } } + } + private let checkServerNotifications = AsyncStream.makeStream(bufferingPolicy: .bufferingNewest(2)) private var maxParallelJobs = 1 - private var task: Task? public var newTaskPollingFrequency = NIO.TimeAmount.milliseconds(1000) public let options: Set