Skip to content

Commit

Permalink
fix: try fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gulivero1773 committed Jun 6, 2024
1 parent 6595328 commit 95aeede
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
16 changes: 10 additions & 6 deletions Sources/HealthChecks/MongoHealthChecks/MongoHealthChecks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ public struct MongoHealthChecks: MongoHealthChecksProtocol {
/// Instance of app as `Application`
public let app: Application

/// Instance of url as `String` for mongo
public let url: String

/// Instance of host as `String` for mongo
public let host: String

/// Instance of port as `Int` for mongo
public let port: Int

/// Initializer for MongoHealthChecks
/// - Parameters:
/// - app: `Application`
/// - url: `String`
public init(app: Application, url: String) {
public init(app: Application, host: String, port: Int) {
self.app = app
self.url = url
self.host = host
self.port = port
}

/// Get mongo connection
Expand Down Expand Up @@ -82,7 +86,7 @@ public struct MongoHealthChecks: MongoHealthChecksProtocol {
/// Get connection of mongo
/// - Returns: `String`
public func getConnection() async -> String {
guard let result = try? await app.mongoRequest?.getConnection(by: url) else {
guard let result = try? await app.mongoRequest?.getConnection(by: host, and: port) else {
return "disconnected"
}
return result
Expand Down
5 changes: 3 additions & 2 deletions Sources/HealthChecks/MongoHealthChecks/MongoRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final class MongoRequest: MongoRequestSendable {
/// Get mongo connection
/// - Parameter url: `String`
/// - Returns: `String`
public func getConnection(by url: String) async throws -> String {
let connect = try await app.client.get(URI(string: "http://localhost:27023" + "?compressors=disabled&gssapiServiceName=mongodb"))
public func getConnection(by host: String, and port: Int) async throws -> String {

let connect = try await app.client.get(URI(string: "http://\(host):\(port)" + "?compressors=disabled&gssapiServiceName=mongodb"))
// await app.mongoCluster?.disconnect()
// app.mongoCluster = nil
// app.mongoCluster = try? MongoCluster(lazyConnectingTo: ConnectionSettings(url))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ import Vapor
public protocol MongoRequestSendable {
/// Get connection description
/// - Returns: `String`
func getConnection(by url: String) async throws -> String
func getConnection(by host: String, and port: Int) async throws -> String
}

0 comments on commit 95aeede

Please sign in to comment.