Skip to content

Commit

Permalink
The usual package tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynne committed Feb 4, 2024
1 parent 54763e7 commit 1a66209
Show file tree
Hide file tree
Showing 29 changed files with 234 additions and 128 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
import PackageDescription

let package = Package(
Expand All @@ -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: [
Expand Down
55 changes: 55 additions & 0 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
@@ -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"),
] }
39 changes: 14 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
<p align="center">
<img
src="https://user-images.githubusercontent.com/1342803/75701575-03f34580-5c82-11ea-9960-f39cdd3c8862.png"
height="64"
alt="Queues"
>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/">
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Docs">
</a>
<a href="http://vapor.team">
<img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
</a>
<a href="LICENSE">
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://github.com/vapor/queues/actions/workflows/test.yml">
<img src="https://github.com/vapor/queues/actions/workflows/test.yml/badge.svg?event=push" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.6-brightgreen.svg" alt="Swift 5.6">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.8-brightgreen.svg" alt="Swift 5.8">
</a>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/queues/assets/1130717/40decf1b-bd9e-4347-99ab-d7e27d60f992">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/queues/assets/1130717/86b36603-bf12-4d0e-8598-45c53caf9608">
<img src="https://github.com/vapor/queues/assets/1130717/86b36603-bf12-4d0e-8598-45c53caf9608" height="96" alt="Queues">
</picture>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/queues/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/queues/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/queues"><img src="https://img.shields.io/codecov/c/github/vapor/queues?style=plastic&logo=codecov&label=codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift57up.svg" alt="Swift 5.7+"></a>
</p>

<br>

12 changes: 6 additions & 6 deletions Sources/Queues/Application+Queues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(...)")
}
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Queues/AsyncJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -77,15 +77,15 @@ extension AsyncJob {
return promise.futureResult
}

public func error(_ context: QueueContext, _ error: Error, _ payload: Payload) -> EventLoopFuture<Void> {
public func error(_ context: QueueContext, _ error: any Error, _ payload: Payload) -> EventLoopFuture<Void> {
let promise = context.eventLoop.makePromise(of: Void.self)
promise.completeWithTask {
try await self.error(context, error, payload)
}
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
}
}
12 changes: 6 additions & 6 deletions Sources/Queues/AsyncJobEventDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> {
public func dispatched(job: JobEventData, eventLoop: any EventLoop) -> EventLoopFuture<Void> {
eventLoop.makeFutureWithTask {
try await self.dispatched(job: job)
}
}

public func didDequeue(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void> {
public func didDequeue(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture<Void> {
eventLoop.makeFutureWithTask {
try await self.didDequeue(jobId: jobId)
}
}

public func success(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void> {
public func success(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture<Void> {
eventLoop.makeFutureWithTask {
try await self.success(jobId: jobId)
}
}

public func error(jobId: String, error: Error, eventLoop: EventLoop) -> EventLoopFuture<Void> {
public func error(jobId: String, error: any Error, eventLoop: any EventLoop) -> EventLoopFuture<Void> {
eventLoop.makeFutureWithTask {
try await self.error(jobId: jobId, error: error)
}
Expand Down
22 changes: 22 additions & 0 deletions Sources/Queues/Docs.docc/images/vapor-queues-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Sources/Queues/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
@@ -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 }
}
}
16 changes: 8 additions & 8 deletions Sources/Queues/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions Sources/Queues/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>

Expand Down Expand Up @@ -64,7 +64,7 @@ extension Job {
/// See `Job`.`error`
public func error(
_ context: QueueContext,
_ error: Error,
_ error: any Error,
_ payload: Payload
) -> EventLoopFuture<Void> {
context.eventLoop.makeSucceededFuture(())
Expand All @@ -79,7 +79,7 @@ extension Job {
return nextRetryIn(attempt: attempt)
}

public func _error(_ context: QueueContext, id: String, _ error: Error, payload: [UInt8]) -> EventLoopFuture<Void> {
public func _error(_ context: QueueContext, id: String, _ error: any Error, payload: [UInt8]) -> EventLoopFuture<Void> {
var contextCopy = context
contextCopy.logger[metadataKey: "job_id"] = .string(id)
do {
Expand All @@ -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<Void>
func _error(_ context: QueueContext, id: String, _ error: Error, payload: [UInt8]) -> EventLoopFuture<Void>
func _error(_ context: QueueContext, id: String, _ error: any Error, payload: [UInt8]) -> EventLoopFuture<Void>
func _nextRetryIn(attempt: Int) -> Int
}
16 changes: 8 additions & 8 deletions Sources/Queues/NotificationHook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>
func dispatched(job: JobEventData, eventLoop: any EventLoop) -> EventLoopFuture<Void>

/// Called when the job is dequeued
/// - Parameters:
/// - jobId: The id of the Job
/// - eventLoop: The eventLoop
func didDequeue(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void>
func didDequeue(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture<Void>


/// Called when the job succeeds
/// - Parameters:
/// - jobId: The id of the Job
/// - eventLoop: The eventLoop
func success(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void>
func success(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture<Void>

/// 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<Void>
func error(jobId: String, error: any Error, eventLoop: any EventLoop) -> EventLoopFuture<Void>
}

extension JobEventDelegate {
public func dispatched(job: JobEventData, eventLoop: EventLoop) -> EventLoopFuture<Void> {
public func dispatched(job: JobEventData, eventLoop: any EventLoop) -> EventLoopFuture<Void> {
eventLoop.future()
}

public func didDequeue(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void> {
public func didDequeue(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture<Void> {
eventLoop.future()
}

public func success(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void> {
public func success(jobId: String, eventLoop: any EventLoop) -> EventLoopFuture<Void> {
eventLoop.future()
}

public func error(jobId: String, error: Error, eventLoop: EventLoop) -> EventLoopFuture<Void> {
public func error(jobId: String, error: any Error, eventLoop: any EventLoop) -> EventLoopFuture<Void> {
eventLoop.future()
}
}
Expand Down
Loading

0 comments on commit 1a66209

Please sign in to comment.