Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gulivero1773 committed Jun 12, 2024
1 parent ec3a04d commit 39ada95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 7 additions & 1 deletion Sources/HealthChecks/Extensions/Application+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,14 @@ extension Application {
}

/// Variable for `MongoDatabase`
public var mongoCluster: MongoCluster? {
public var healthCheckMongoCluster: MongoCluster? {
get { storage[MongoClusterKey.self] }
set { storage[MongoClusterKey.self] = newValue }
}

/// Initialize MongoDB
/// - Parameter connectionString: URI as `String`. Example: "mongodb://localhost/myapp
public func initializeHealthCheckMongoCluster(connectionString: String) async throws {
self.healthCheckMongoCluster = try await MongoCluster(connectingTo: ConnectionSettings(connectionString))
}
}
13 changes: 4 additions & 9 deletions Sources/HealthChecks/MongoHealthChecks/MongoRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ public final class MongoRequest: MongoRequestSendable {
/// - Parameter port: `String`
/// - Returns: `String`
public func getConnection(by host: String, and port: String) async throws -> String {
let connection = "\(app.mongoCluster?.connectionState ?? .disconnected)"
let connection = "\(app.healthCheckMongoCluster?.connectionState ?? .disconnected)"
if connection.contains("disconnected") {
app.logger.error("ERROR: MongoDB not connect")
}
return connection
}
}

extension Application {
/// Initialize MongoDB
/// - Parameter connectionString: URI as `String`. Example: "mongodb://localhost/myapp
public func initializeMongoClusterLibrary(connectionString: String) async throws {
self.mongoCluster = try await MongoCluster(connectingTo: ConnectionSettings(connectionString))
}
}

0 comments on commit 39ada95

Please sign in to comment.