diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index acc6159..32814d6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,4 @@ on: jobs: unit-tests: - uses: vapor/ci/.github/workflows/run-unit-tests.yml@reusable-workflows - with: - with_coverage: true - with_tsan: true + uses: vapor/ci/.github/workflows/run-unit-tests.yml@main diff --git a/Package.swift b/Package.swift index a52f090..36d739d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.6 +// swift-tools-version:5.7 import PackageDescription let package = Package( @@ -14,8 +14,8 @@ let package = Package( .library(name: "XCTQueues", targets: ["XCTQueues"]) ], dependencies: [ - .package(url: "https://github.com/vapor/vapor.git", from: "4.76.2"), - .package(url: "https://github.com/apple/swift-nio.git", from: "2.53.0"), + .package(url: "https://github.com/vapor/vapor.git", from: "4.79.0"), + .package(url: "https://github.com/apple/swift-nio.git", from: "2.58.0"), ], targets: [ .target(name: "Queues", dependencies: [ diff --git a/Package@swift-5.9.swift b/Package@swift-5.9.swift new file mode 100644 index 0000000..452f2df --- /dev/null +++ b/Package@swift-5.9.swift @@ -0,0 +1,55 @@ +// swift-tools-version:5.9 +import PackageDescription + +let package = Package( + name: "queues", + platforms: [ + .macOS(.v10_15), + .iOS(.v13), + .watchOS(.v6), + .tvOS(.v13), + ], + products: [ + .library(name: "Queues", targets: ["Queues"]), + .library(name: "XCTQueues", targets: ["XCTQueues"]) + ], + dependencies: [ + .package(url: "https://github.com/vapor/vapor.git", from: "4.92.1"), + .package(url: "https://github.com/apple/swift-nio.git", from: "2.63.0"), + ], + targets: [ + .target( + name: "Queues", + dependencies: [ + .product(name: "Vapor", package: "vapor"), + .product(name: "NIOCore", package: "swift-nio"), + ], + swiftSettings: swiftSettings + ), + .target( + name: "XCTQueues", + dependencies: [ + .target(name: "Queues"), + ], + swiftSettings: swiftSettings + ), + .testTarget( + name: "QueuesTests", + dependencies: [ + .target(name: "Queues"), + .target(name: "XCTQueues"), + .product(name: "XCTVapor", package: "vapor"), + ], + swiftSettings: swiftSettings + ), + ] +) + +var swiftSettings: [SwiftSetting] { [ + .enableUpcomingFeature("ForwardTrailingClosures"), + .enableUpcomingFeature("ExistentialAny"), + .enableUpcomingFeature("ConciseMagicFile"), + .enableUpcomingFeature("DisableOutwardActorInference"), + .enableUpcomingFeature("StrictConcurrency"), + .enableExperimentalFeature("StrictConcurrency=complete"), +] } diff --git a/README.md b/README.md index fac4104..710c1d1 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,18 @@

- Queues -
-
- - Docs - - - Team Chat - - - MIT License - - - Continuous Integration - - - Swift 5.6 - - - Swift 5.8 - + + + + Queues + +
+
+Documentation +Team Chat +MIT License +Continuous Integration + +Swift 5.7+

+
diff --git a/Sources/Queues/Application+Queues.swift b/Sources/Queues/Application+Queues.swift index b217eae..f13d1d8 100644 --- a/Sources/Queues/Application+Queues.swift +++ b/Sources/Queues/Application+Queues.swift @@ -24,7 +24,7 @@ extension Application { final class Storage { public var configuration: QueuesConfiguration private (set) var commands: [QueuesCommand] - var driver: QueuesDriver? + var driver: (any QueuesDriver)? public init(_ application: Application) { self.configuration = .init(logger: application.logger) @@ -58,12 +58,12 @@ extension Application { } /// Returns the default `Queue` - public var queue: Queue { + public var queue: any Queue { self.queue(.default) } /// The selected `QueuesDriver` - public var driver: QueuesDriver { + public var driver: any QueuesDriver { guard let driver = self.storage.driver else { fatalError("No Queues driver configured. Configure with app.queues.use(...)") } @@ -87,8 +87,8 @@ extension Application { public func queue( _ name: QueueName, logger: Logger? = nil, - on eventLoop: EventLoop? = nil - ) -> Queue { + on eventLoop: (any EventLoop)? = nil + ) -> any Queue { return self.driver.makeQueue( with: .init( queueName: name, @@ -120,7 +120,7 @@ extension Application { /// Choose which driver to use /// - Parameter driver: The driver - public func use(custom driver: QueuesDriver) { + public func use(custom driver: any QueuesDriver) { self.storage.driver = driver } diff --git a/Sources/Queues/AsyncJob.swift b/Sources/Queues/AsyncJob.swift index 197e77e..3df36f4 100644 --- a/Sources/Queues/AsyncJob.swift +++ b/Sources/Queues/AsyncJob.swift @@ -23,7 +23,7 @@ public protocol AsyncJob: Job { /// - payload: The typed payload for the job func error( _ context: QueueContext, - _ error: Error, + _ error: any Error, _ payload: Payload ) async throws @@ -77,7 +77,7 @@ extension AsyncJob { return promise.futureResult } - public func error(_ context: QueueContext, _ error: Error, _ payload: Payload) -> EventLoopFuture { + public func error(_ context: QueueContext, _ error: any Error, _ payload: Payload) -> EventLoopFuture { let promise = context.eventLoop.makePromise(of: Void.self) promise.completeWithTask { try await self.error(context, error, payload) @@ -85,7 +85,7 @@ extension AsyncJob { return promise.futureResult } - public func error(_ context: QueueContext, _ error: Error, _ payload: Payload) async throws { + public func error(_ context: QueueContext, _ error: any Error, _ payload: Payload) async throws { return } } diff --git a/Sources/Queues/AsyncJobEventDelegate.swift b/Sources/Queues/AsyncJobEventDelegate.swift index d76fad4..6aa1711 100644 --- a/Sources/Queues/AsyncJobEventDelegate.swift +++ b/Sources/Queues/AsyncJobEventDelegate.swift @@ -21,34 +21,34 @@ public protocol AsyncJobEventDelegate: JobEventDelegate { /// - Parameters: /// - jobId: The id of the Job /// - error: The error that caused the job to fail - func error(jobId: String, error: Error) async throws + func error(jobId: String, error: any Error) async throws } extension AsyncJobEventDelegate { public func dispatched(job: JobEventData) async throws { } public func didDequeue(jobId: String) async throws { } public func success(jobId: String) async throws { } - public func error(jobId: String, error: Error) async throws { } + public func error(jobId: String, error: any Error) async throws { } - public func dispatched(job: JobEventData, eventLoop: EventLoop) -> EventLoopFuture { + public func dispatched(job: JobEventData, eventLoop: any EventLoop) -> EventLoopFuture { eventLoop.makeFutureWithTask { try await self.dispatched(job: job) } } - public func didDequeue(jobId: String, eventLoop: EventLoop) -> EventLoopFuture { + public func didDequeue(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture { eventLoop.makeFutureWithTask { try await self.didDequeue(jobId: jobId) } } - public func success(jobId: String, eventLoop: EventLoop) -> EventLoopFuture { + public func success(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture { eventLoop.makeFutureWithTask { try await self.success(jobId: jobId) } } - public func error(jobId: String, error: Error, eventLoop: EventLoop) -> EventLoopFuture { + public func error(jobId: String, error: any Error, eventLoop: any EventLoop) -> EventLoopFuture { eventLoop.makeFutureWithTask { try await self.error(jobId: jobId, error: error) } diff --git a/Sources/Queues/Docs.docc/images/vapor-queues-logo.svg b/Sources/Queues/Docs.docc/images/vapor-queues-logo.svg new file mode 100644 index 0000000..67f5902 --- /dev/null +++ b/Sources/Queues/Docs.docc/images/vapor-queues-logo.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/Sources/Queues/Docs.docc/theme-settings.json b/Sources/Queues/Docs.docc/theme-settings.json new file mode 100644 index 0000000..dac7300 --- /dev/null +++ b/Sources/Queues/Docs.docc/theme-settings.json @@ -0,0 +1,21 @@ +{ + "theme": { + "aside": { "border-radius": "6px", "border-style": "double", "border-width": "3px" }, + "border-radius": "0", + "button": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" }, + "code": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" }, + "color": { + "queues": "#e8665a", + "documentation-intro-fill": "radial-gradient(circle at top, var(--color-queues) 30%, #000 100%)", + "documentation-intro-accent": "var(--color-queues)", + "logo-base": { "dark": "#fff", "light": "#000" }, + "logo-shape": { "dark": "#000", "light": "#fff" }, + "fill": { "dark": "#000", "light": "#fff" } + }, + "icons": { "technology": "/queues/images/vapor-queues-logo.svg" } + }, + "features": { + "quickNavigation": { "enable": true }, + "i18n": { "enable": true } + } +} diff --git a/Sources/Queues/Exports.swift b/Sources/Queues/Exports.swift index 3d38063..30084c7 100644 --- a/Sources/Queues/Exports.swift +++ b/Sources/Queues/Exports.swift @@ -2,18 +2,18 @@ @_documentation(visibility: internal) @_exported import struct Foundation.Date @_documentation(visibility: internal) @_exported import struct Logging.Logger -@_documentation(visibility: internal) @_exported import class NIO.EventLoopFuture -@_documentation(visibility: internal) @_exported import struct NIO.EventLoopPromise -@_documentation(visibility: internal) @_exported import protocol NIO.EventLoop -@_documentation(visibility: internal) @_exported import struct NIO.TimeAmount +@_documentation(visibility: internal) @_exported import class NIOCore.EventLoopFuture +@_documentation(visibility: internal) @_exported import struct NIOCore.EventLoopPromise +@_documentation(visibility: internal) @_exported import protocol NIOCore.EventLoop +@_documentation(visibility: internal) @_exported import struct NIOCore.TimeAmount #else @_exported import struct Foundation.Date @_exported import struct Logging.Logger -@_exported import class NIO.EventLoopFuture -@_exported import struct NIO.EventLoopPromise -@_exported import protocol NIO.EventLoop -@_exported import struct NIO.TimeAmount +@_exported import class NIOCore.EventLoopFuture +@_exported import struct NIOCore.EventLoopPromise +@_exported import protocol NIOCore.EventLoop +@_exported import struct NIOCore.TimeAmount #endif diff --git a/Sources/Queues/Job.swift b/Sources/Queues/Job.swift index 80dfc68..dbd975d 100644 --- a/Sources/Queues/Job.swift +++ b/Sources/Queues/Job.swift @@ -24,7 +24,7 @@ public protocol Job: AnyJob { /// - payload: The typed payload for the job func error( _ context: QueueContext, - _ error: Error, + _ error: any Error, _ payload: Payload ) -> EventLoopFuture @@ -64,7 +64,7 @@ extension Job { /// See `Job`.`error` public func error( _ context: QueueContext, - _ error: Error, + _ error: any Error, _ payload: Payload ) -> EventLoopFuture { context.eventLoop.makeSucceededFuture(()) @@ -79,7 +79,7 @@ extension Job { return nextRetryIn(attempt: attempt) } - public func _error(_ context: QueueContext, id: String, _ error: Error, payload: [UInt8]) -> EventLoopFuture { + public func _error(_ context: QueueContext, id: String, _ error: any Error, payload: [UInt8]) -> EventLoopFuture { var contextCopy = context contextCopy.logger[metadataKey: "job_id"] = .string(id) do { @@ -105,6 +105,6 @@ public protocol AnyJob { /// The name of the `Job` static var name: String { get } func _dequeue(_ context: QueueContext, id: String, payload: [UInt8]) -> EventLoopFuture - func _error(_ context: QueueContext, id: String, _ error: Error, payload: [UInt8]) -> EventLoopFuture + func _error(_ context: QueueContext, id: String, _ error: any Error, payload: [UInt8]) -> EventLoopFuture func _nextRetryIn(attempt: Int) -> Int } diff --git a/Sources/Queues/NotificationHook.swift b/Sources/Queues/NotificationHook.swift index ea317d9..f4c7223 100644 --- a/Sources/Queues/NotificationHook.swift +++ b/Sources/Queues/NotificationHook.swift @@ -8,43 +8,43 @@ public protocol JobEventDelegate { /// - Parameters: /// - job: The `JobData` associated with the job /// - eventLoop: The eventLoop - func dispatched(job: JobEventData, eventLoop: EventLoop) -> EventLoopFuture + func dispatched(job: JobEventData, eventLoop: any EventLoop) -> EventLoopFuture /// Called when the job is dequeued /// - Parameters: /// - jobId: The id of the Job /// - eventLoop: The eventLoop - func didDequeue(jobId: String, eventLoop: EventLoop) -> EventLoopFuture + func didDequeue(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture /// Called when the job succeeds /// - Parameters: /// - jobId: The id of the Job /// - eventLoop: The eventLoop - func success(jobId: String, eventLoop: EventLoop) -> EventLoopFuture + func success(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture /// Called when the job returns an error /// - Parameters: /// - jobId: The id of the Job /// - error: The error that caused the job to fail /// - eventLoop: The eventLoop - func error(jobId: String, error: Error, eventLoop: EventLoop) -> EventLoopFuture + func error(jobId: String, error: any Error, eventLoop: any EventLoop) -> EventLoopFuture } extension JobEventDelegate { - public func dispatched(job: JobEventData, eventLoop: EventLoop) -> EventLoopFuture { + public func dispatched(job: JobEventData, eventLoop: any EventLoop) -> EventLoopFuture { eventLoop.future() } - public func didDequeue(jobId: String, eventLoop: EventLoop) -> EventLoopFuture { + public func didDequeue(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture { eventLoop.future() } - public func success(jobId: String, eventLoop: EventLoop) -> EventLoopFuture { + public func success(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture { eventLoop.future() } - public func error(jobId: String, error: Error, eventLoop: EventLoop) -> EventLoopFuture { + public func error(jobId: String, error: any Error, eventLoop: any EventLoop) -> EventLoopFuture { eventLoop.future() } } diff --git a/Sources/Queues/Queue.swift b/Sources/Queues/Queue.swift index cfef68f..9041dc8 100644 --- a/Sources/Queues/Queue.swift +++ b/Sources/Queues/Queue.swift @@ -31,7 +31,7 @@ public protocol Queue { extension Queue { /// The EventLoop for a job queue - public var eventLoop: EventLoop { + public var eventLoop: any EventLoop { self.context.eventLoop } diff --git a/Sources/Queues/QueueContext.swift b/Sources/Queues/QueueContext.swift index 6ef924e..c5a706d 100644 --- a/Sources/Queues/QueueContext.swift +++ b/Sources/Queues/QueueContext.swift @@ -17,7 +17,7 @@ public struct QueueContext { public var logger: Logger /// An event loop to run the process on - public let eventLoop: EventLoop + public let eventLoop: any EventLoop /// Creates a new JobContext /// - Parameters: @@ -31,7 +31,7 @@ public struct QueueContext { configuration: QueuesConfiguration, application: Application, logger: Logger, - on eventLoop: EventLoop + on eventLoop: any EventLoop ) { self.queueName = queueName self.configuration = configuration @@ -41,13 +41,13 @@ public struct QueueContext { } /// Returns the default job `Queue` - public var queue: Queue { + public var queue: any Queue { self.queues(.default) } /// Returns the specific job `Queue` for the given queue name /// - Parameter queue: The queue name - public func queues(_ queue: QueueName) -> Queue { + public func queues(_ queue: QueueName) -> any Queue { self.application.queues.queue( queue, logger: self.logger, diff --git a/Sources/Queues/QueueName.swift b/Sources/Queues/QueueName.swift index a7bfe8b..a062ca0 100644 --- a/Sources/Queues/QueueName.swift +++ b/Sources/Queues/QueueName.swift @@ -1,23 +1,23 @@ /// A specific queue that jobs are run on. public struct QueueName { /// The default queue that jobs are run on - public static let `default` = QueueName(string: "default") + public static let `default` = Self(string: "default") /// The name of the queue public let string: String - /// Creates a new `QueueType` + /// Creates a new ``QueueName`` /// - /// - Parameter name: The name of the `QueueType` + /// - Parameter name: The name of the queue public init(string: String) { self.string = string } /// Makes the name of the queue /// - /// - Parameter persistanceKey: The base persistence key + /// - Parameter persistenceKey: The base persistence key /// - Returns: A string of the queue's fully qualified name - public func makeKey(with persistanceKey: String) -> String { - return persistanceKey + "[\(self.string)]" + public func makeKey(with persistenceKey: String) -> String { + "\(persistenceKey)[\(self.string)]" } } diff --git a/Sources/Queues/QueueWorker.swift b/Sources/Queues/QueueWorker.swift index b375188..f2bf7fb 100644 --- a/Sources/Queues/QueueWorker.swift +++ b/Sources/Queues/QueueWorker.swift @@ -12,7 +12,7 @@ extension Queue { public struct QueueWorker { let queue: Queue - init(queue: Queue) { + init(queue: any Queue) { self.queue = queue } @@ -78,7 +78,7 @@ public struct QueueWorker { private func run( id: JobIdentifier, name: String, - job: AnyJob, + job: any AnyJob, payload: [UInt8], logger: Logger, remainingTries: Int, @@ -139,13 +139,13 @@ public struct QueueWorker { private func retry( id: JobIdentifier, name: String, - job: AnyJob, + job: any AnyJob, payload: [UInt8], logger: Logger, remainingTries: Int, attempts: Int?, jobData: JobData, - error: Error + error: any Error ) -> EventLoopFuture { let attempts = attempts ?? 0 let delayInSeconds = job._nextRetryIn(attempt: attempts + 1) diff --git a/Sources/Queues/QueuesCommand.swift b/Sources/Queues/QueuesCommand.swift index e4af895..613b404 100644 --- a/Sources/Queues/QueuesCommand.swift +++ b/Sources/Queues/QueuesCommand.swift @@ -35,12 +35,12 @@ public final class QueuesCommand: Command { private var jobTasks: [RepeatedTask] private var scheduledTasks: [String: AnyScheduledJob.Task] private var lock: NIOLock - private var signalSources: [DispatchSourceSignal] + private var signalSources: [any DispatchSourceSignal] private var didShutdown: Bool private let isShuttingDown: ManagedAtomic - private var eventLoopGroup: EventLoopGroup { + private var eventLoopGroup: any EventLoopGroup { self.application.eventLoopGroup } diff --git a/Sources/Queues/QueuesDriver.swift b/Sources/Queues/QueuesDriver.swift index 1853a74..b580f5f 100644 --- a/Sources/Queues/QueuesDriver.swift +++ b/Sources/Queues/QueuesDriver.swift @@ -2,7 +2,7 @@ public protocol QueuesDriver { /// Makes the queue worker /// - Parameter context: The context of the job - func makeQueue(with context: QueueContext) -> Queue + func makeQueue(with context: QueueContext) -> any Queue /// Shuts down the driver func shutdown() diff --git a/Sources/Queues/QueuesEventLoopPreference.swift b/Sources/Queues/QueuesEventLoopPreference.swift index aa9e7fe..ffe1426 100644 --- a/Sources/Queues/QueuesEventLoopPreference.swift +++ b/Sources/Queues/QueuesEventLoopPreference.swift @@ -1,11 +1,3 @@ -// -// JobsEventLoopPreference.swift -// -// -// Created by Jimmy McDermott on 10/24/19. -// - -import Foundation import NIOCore /// Determines which event loop the jobs worker uses while executing jobs. @@ -17,10 +9,10 @@ public enum QueuesEventLoopPreference { /// called back (delegated to) on the supplied EventLoop. /// If possible, the connection should also be on this EventLoop for /// improved performance. - case delegate(on: EventLoop) + case delegate(on: any EventLoop) /// Returns the delegate EventLoop given an EventLoopGroup. - public func delegate(for eventLoopGroup: EventLoopGroup) -> EventLoop { + public func delegate(for eventLoopGroup: any EventLoopGroup) -> any EventLoop { switch self { case .indifferent: return eventLoopGroup.next() diff --git a/Sources/Queues/RepeatedTask+Cancel.swift b/Sources/Queues/RepeatedTask+Cancel.swift index 7f2ac0b..c734c71 100644 --- a/Sources/Queues/RepeatedTask+Cancel.swift +++ b/Sources/Queues/RepeatedTask+Cancel.swift @@ -1,7 +1,7 @@ import NIOCore extension RepeatedTask { - func syncCancel(on eventLoop: EventLoop) { + func syncCancel(on eventLoop: any EventLoop) { do { let promise = eventLoop.makePromise(of: Void.self) self.cancel(promise: promise) @@ -10,4 +10,4 @@ extension RepeatedTask { print("failed cancelling repeated task \(error)") } } -} \ No newline at end of file +} diff --git a/Sources/Queues/Request+Queues.swift b/Sources/Queues/Request+Queues.swift index 6a1e6f4..63d04f1 100644 --- a/Sources/Queues/Request+Queues.swift +++ b/Sources/Queues/Request+Queues.swift @@ -4,13 +4,13 @@ import NIOCore extension Request { /// Returns the default job `Queue` - public var queue: Queue { + public var queue: any Queue { self.queues(.default) } /// Returns the specific job `Queue` for the given queue name /// - Parameter queue: The queue name - public func queues(_ queue: QueueName) -> Queue { + public func queues(_ queue: QueueName) -> any Queue { self.application.queues.queue( queue, logger: self.logger, diff --git a/Sources/Queues/ScheduleBuilder.swift b/Sources/Queues/ScheduleBuilder.swift index 9a6a2b4..ff7f404 100644 --- a/Sources/Queues/ScheduleBuilder.swift +++ b/Sources/Queues/ScheduleBuilder.swift @@ -447,4 +447,3 @@ public final class ScheduleBuilder { self.millisecond = 0 } } - diff --git a/Sources/Queues/ScheduledJob.swift b/Sources/Queues/ScheduledJob.swift index b1be2ce..d44ecf0 100644 --- a/Sources/Queues/ScheduledJob.swift +++ b/Sources/Queues/ScheduledJob.swift @@ -18,7 +18,7 @@ class AnyScheduledJob { let job: ScheduledJob let scheduler: ScheduleBuilder - init(job: ScheduledJob, scheduler: ScheduleBuilder) { + init(job: any ScheduledJob, scheduler: ScheduleBuilder) { self.job = job self.scheduler = scheduler } diff --git a/Sources/XCTQueues/Docs.docc/images/vapor-queues-logo.svg b/Sources/XCTQueues/Docs.docc/images/vapor-queues-logo.svg new file mode 100644 index 0000000..67f5902 --- /dev/null +++ b/Sources/XCTQueues/Docs.docc/images/vapor-queues-logo.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/Sources/XCTQueues/Docs.docc/theme-settings.json b/Sources/XCTQueues/Docs.docc/theme-settings.json new file mode 100644 index 0000000..dac7300 --- /dev/null +++ b/Sources/XCTQueues/Docs.docc/theme-settings.json @@ -0,0 +1,21 @@ +{ + "theme": { + "aside": { "border-radius": "6px", "border-style": "double", "border-width": "3px" }, + "border-radius": "0", + "button": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" }, + "code": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" }, + "color": { + "queues": "#e8665a", + "documentation-intro-fill": "radial-gradient(circle at top, var(--color-queues) 30%, #000 100%)", + "documentation-intro-accent": "var(--color-queues)", + "logo-base": { "dark": "#fff", "light": "#000" }, + "logo-shape": { "dark": "#000", "light": "#fff" }, + "fill": { "dark": "#000", "light": "#fff" } + }, + "icons": { "technology": "/queues/images/vapor-queues-logo.svg" } + }, + "features": { + "quickNavigation": { "enable": true }, + "i18n": { "enable": true } + } +} diff --git a/Sources/XCTQueues/TestQueueDriver.swift b/Sources/XCTQueues/TestQueueDriver.swift index a4ed842..508ee97 100644 --- a/Sources/XCTQueues/TestQueueDriver.swift +++ b/Sources/XCTQueues/TestQueueDriver.swift @@ -19,7 +19,7 @@ struct TestQueuesDriver: QueuesDriver { self.lock = .init() } - func makeQueue(with context: QueueContext) -> Queue { + func makeQueue(with context: QueueContext) -> any Queue { TestQueue(lock: self.lock, context: context) } diff --git a/Tests/QueuesTests/AsyncQueueTests.swift b/Tests/QueuesTests/AsyncQueueTests.swift index 7c6c732..61a376a 100644 --- a/Tests/QueuesTests/AsyncQueueTests.swift +++ b/Tests/QueuesTests/AsyncQueueTests.swift @@ -1,12 +1,6 @@ import Queues -import Foundation -import Vapor import XCTest import XCTVapor -import XCTQueues -@testable import Vapor -import NIOCore -import NIOConcurrencyHelpers final class AsyncQueueTests: XCTestCase { func testAsyncJob() throws { @@ -50,7 +44,7 @@ struct MyAsyncJob: AsyncJob { } func dequeue(_ context: QueueContext, _ payload: Data) async throws { - promise.succeed(()) + self.promise.succeed(()) return } } diff --git a/Tests/QueuesTests/QueueTests.swift b/Tests/QueuesTests/QueueTests.swift index 562287b..537fbb9 100644 --- a/Tests/QueuesTests/QueueTests.swift +++ b/Tests/QueuesTests/QueueTests.swift @@ -1,13 +1,9 @@ import Atomics import Queues -import Vapor -import Foundation import XCTest import XCTVapor import XCTQueues -import NIOCore import NIOConcurrencyHelpers -@testable import Vapor final class QueueTests: XCTestCase { func testVaporIntegrationWithInProcessJob() throws { @@ -15,7 +11,7 @@ final class QueueTests: XCTestCase { app.queues.use(.test) defer { app.shutdown() } - let jobSignal = app.eventLoopGroup.next().makePromise(of: String.self) + let jobSignal = app.eventLoopGroup.any().makePromise(of: String.self) app.queues.add(Foo(promise: jobSignal)) try app.queues.startInProcessJobs(on: .default) @@ -37,7 +33,7 @@ final class QueueTests: XCTestCase { defer { app.shutdown() } app.queues.use(.test) - let promise = app.eventLoopGroup.next().makePromise(of: String.self) + let promise = app.eventLoopGroup.any().makePromise(of: String.self) app.queues.add(Foo(promise: promise)) app.get("foo") { req in @@ -69,7 +65,7 @@ final class QueueTests: XCTestCase { defer { app.shutdown() } app.queues.use(.test) - let promise = app.eventLoopGroup.next().makePromise(of: String.self) + let promise = app.eventLoopGroup.any().makePromise(of: String.self) app.queues.add(Foo(promise: promise)) app.get("foo") { req in @@ -161,8 +157,8 @@ final class QueueTests: XCTestCase { app.queues.schedule(FailingScheduledJob()).everySecond() try app.queues.startScheduledJobs() - let promise = app.eventLoopGroup.next().makePromise(of: Void.self) - app.eventLoopGroup.next().scheduleTask(in: .seconds(1)) { () -> Void in + let promise = app.eventLoopGroup.any().makePromise(of: Void.self) + app.eventLoopGroup.any().scheduleTask(in: .seconds(1)) { () -> Void in promise.succeed(()) } try promise.futureResult.wait() @@ -176,7 +172,7 @@ final class QueueTests: XCTestCase { let app = Application(.testing, .shared(eventLoopGroup)) defer { app.shutdown() } - let count = app.eventLoopGroup.next().makePromise(of: Int.self) + let count = app.eventLoopGroup.any().makePromise(of: Int.self) app.queues.use(custom: WorkerCountDriver(count: count)) // Limit worker count to less than 4 threads app.queues.configuration.workerCount = 2 @@ -190,7 +186,7 @@ final class QueueTests: XCTestCase { defer { app.shutdown() } app.queues.use(.test) - let promise = app.eventLoopGroup.next().makePromise(of: String.self) + let promise = app.eventLoopGroup.any().makePromise(of: String.self) app.queues.add(Foo(promise: promise)) app.queues.add(SuccessHook()) app.queues.add(ErrorHook()) @@ -358,11 +354,11 @@ final class WorkerCountDriver: QueuesDriver { self.recordedEventLoops = [] } - func makeQueue(with context: QueueContext) -> Queue { + func makeQueue(with context: QueueContext) -> any Queue { WorkerCountQueue(driver: self, context: context) } - func record(eventLoop: EventLoop) { + func record(eventLoop: any EventLoop) { self.lock.lock() defer { self.lock.unlock() } let previousCount = self.recordedEventLoops.count @@ -439,7 +435,7 @@ struct Foo: Job { return context.eventLoop.makeSucceededFuture(()) } - func error(_ context: QueueContext, _ error: Error, _ data: Data) -> EventLoopFuture { + func error(_ context: QueueContext, _ error: any Error, _ data: Data) -> EventLoopFuture { self.promise.fail(error) return context.eventLoop.makeSucceededFuture(()) } @@ -454,7 +450,7 @@ struct Bar: Job { return context.eventLoop.makeFailedFuture(Abort(.badRequest)) } - func error(_ context: QueueContext, _ error: Error, _ data: Data) -> EventLoopFuture { + func error(_ context: QueueContext, _ error: any Error, _ data: Data) -> EventLoopFuture { return context.eventLoop.makeSucceededFuture(()) } } @@ -468,7 +464,7 @@ struct Baz: Job { return context.eventLoop.makeFailedFuture(Abort(.badRequest)) } - func error(_ context: QueueContext, _ error: Error, _ data: Data) -> EventLoopFuture { + func error(_ context: QueueContext, _ error: any Error, _ data: Data) -> EventLoopFuture { return context.eventLoop.makeSucceededFuture(()) } diff --git a/Tests/QueuesTests/ScheduleBuilderTests.swift b/Tests/QueuesTests/ScheduleBuilderTests.swift index acd0f2f..62d6de2 100644 --- a/Tests/QueuesTests/ScheduleBuilderTests.swift +++ b/Tests/QueuesTests/ScheduleBuilderTests.swift @@ -1,7 +1,6 @@ import Foundation import Queues import XCTest -import NIOCore final class ScheduleBuilderTests: XCTestCase { func testHourlyBuilder() throws { @@ -137,7 +136,6 @@ final class ScheduleBuilderTests: XCTestCase { } func testCustomCalendarBuilder() throws { - let est = Calendar.calendar(timezone: "EST") let mst = Calendar.calendar(timezone: "MST") @@ -160,7 +158,7 @@ final class ScheduleBuilderTests: XCTestCase { final class Cleanup: ScheduledJob { func run(context: QueueContext) -> EventLoopFuture { - return context.eventLoop.makeSucceededFuture(()) + context.eventLoop.makeSucceededFuture(()) } }