Skip to content

Commit

Permalink
run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Nov 27, 2024
1 parent ba57892 commit e035a80
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
24 changes: 15 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ let package = Package(
name: "swift-jobs-redis",
platforms: [.macOS(.v14), .iOS(.v17), .tvOS(.v17)],
products: [
.library(name: "JobsRedis", targets: ["JobsRedis"]),
.library(name: "JobsRedis", targets: ["JobsRedis"])
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/swift-jobs.git", from: "1.0.0-beta.4"),
.package(url: "https://github.com/swift-server/RediStack.git", from: "1.4.0"),
],
targets: [
.target(name: "JobsRedis", dependencies: [
.product(name: "Jobs", package: "swift-jobs"),
.product(name: "RediStack", package: "RediStack"),
]),
.testTarget(name: "JobsRedisTests", dependencies: [
.byName(name: "JobsRedis"),
.product(name: "Jobs", package: "swift-jobs"),
]),
.target(
name: "JobsRedis",
dependencies: [
.product(name: "Jobs", package: "swift-jobs"),
.product(name: "RediStack", package: "RediStack"),
]
),
.testTarget(
name: "JobsRedisTests",
dependencies: [
.byName(name: "JobsRedis"),
.product(name: "Jobs", package: "swift-jobs"),
]
),
]
)
28 changes: 15 additions & 13 deletions Sources/JobsRedis/RedisJobQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
//===----------------------------------------------------------------------===//

import Atomics
import Jobs
import NIOCore
import RediStack

import struct Foundation.Data
import struct Foundation.Date
import class Foundation.JSONDecoder
import struct Foundation.UUID
import Jobs
import NIOCore
import RediStack

/// Redis implementation of job queue driver
public final class RedisJobQueue: JobQueueDriver {
Expand All @@ -37,11 +38,12 @@ public final class RedisJobQueue: JobQueueDriver {
public init(_ value: String) {
let parts = value.components(separatedBy: ":")
self.id = parts[0]
self.delayUntil = if parts.count > 1 {
Self.toMillisecondsFromString(value: parts[1])
} else {
0
}
self.delayUntil =
if parts.count > 1 {
Self.toMillisecondsFromString(value: parts[1])
} else {
0
}
}

static func toMilliseconds(value: Double?) -> Int64 {
Expand All @@ -52,7 +54,7 @@ public final class RedisJobQueue: JobQueueDriver {
}

static func toMillisecondsFromString(value: String) -> Int64 {
return Int64(value) ?? 0
Int64(value) ?? 0
}

func isDelayed() -> Bool {
Expand Down Expand Up @@ -153,7 +155,7 @@ public final class RedisJobQueue: JobQueueDriver {
/// - Parameter key: Metadata key
/// - Returns: Associated ByteBuffer
public func getMetadata(_ key: String) async throws -> ByteBuffer? {
return try await self.redisConnectionPool.wrappedValue.get(.init(key)).get().byteBuffer
try await self.redisConnectionPool.wrappedValue.get(.init(key)).get().byteBuffer
}

/// Set job queue metadata
Expand Down Expand Up @@ -231,7 +233,7 @@ public final class RedisJobQueue: JobQueueDriver {
}

func get(jobId: JobID) async throws -> ByteBuffer? {
return try await self.redisConnectionPool.wrappedValue.get(jobId.redisKey).get().byteBuffer
try await self.redisConnectionPool.wrappedValue.get(jobId.redisKey).get().byteBuffer
}

func set(jobId: JobID, buffer: ByteBuffer) async throws {
Expand Down Expand Up @@ -264,7 +266,7 @@ extension RedisJobQueue {
}

public func makeAsyncIterator() -> AsyncIterator {
return .init(queue: self)
.init(queue: self)
}
}

Expand Down Expand Up @@ -292,6 +294,6 @@ extension ByteBuffer {
}

public func convertedToRESPValue() -> RESPValue {
return .bulkString(self)
.bulkString(self)
}
}
9 changes: 6 additions & 3 deletions Tests/JobsRedisTests/RedisJobsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import Atomics
import Foundation
import Jobs
@testable import JobsRedis
import Logging
import NIOConcurrencyHelpers
import NIOCore
Expand All @@ -24,6 +23,8 @@ import RediStack
import ServiceLifecycle
import XCTest

@testable import JobsRedis

extension XCTestExpectation {
convenience init(description: String, expectedFulfillmentCount: Int) {
self.init(description: description)
Expand Down Expand Up @@ -209,7 +210,8 @@ final class RedisJobsTests: XCTestCase {
let pendingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.queueKey).get()
XCTAssertEqual(pendingJobs, 0)

let processingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.processingQueueKey).get()
let processingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.processingQueueKey)
.get()
XCTAssertEqual(processingJobs, 0)
}
XCTAssertEqual(currentJobTryCount.withLockedValue { $0 }, 2)
Expand Down Expand Up @@ -296,7 +298,8 @@ final class RedisJobsTests: XCTestCase {
let pendingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.queueKey).get()
XCTAssertEqual(pendingJobs, 0)
let failedJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.failedQueueKey).get()
let processingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.processingQueueKey).get()
let processingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.processingQueueKey)
.get()
XCTAssertEqual(failedJobs + processingJobs, 1)
}
}
Expand Down

0 comments on commit e035a80

Please sign in to comment.