Skip to content

Commit 8a752fa

Browse files
committed
Read redis hostname from REDIS_HOST env variable
1 parent a495de9 commit 8a752fa

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Sources/App/Core/Dependencies/EnvironmentClient.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct EnvironmentClient {
5959
case repositorySaveFailed
6060
case repositorySaveUniqueViolation
6161
}
62+
var redisHostname: @Sendable () -> String = { "redis" }
6263
var shouldFail: @Sendable (_ failureMode: FailureMode) -> Bool = { _ in XCTFail("shouldFail"); return false }
6364
var siteURL: @Sendable () -> String = { XCTFail("siteURL"); return "" }
6465
}
@@ -126,6 +127,12 @@ extension EnvironmentClient: DependencyKey {
126127
Environment.get("PROCESSING_BUILD_BACKLOG").flatMap(\.asBool) ?? false
127128
},
128129
random: { range in Double.random(in: range) },
130+
redisHostname: {
131+
// Defaulting this to `redis`, which is the service name in `app.yml`.
132+
// This is also why `REDIS_HOST` is not set as an env variable in `app.yml`,
133+
// it's a known value that needs no configuration outside of local use for testing.
134+
Environment.get("REDIS_HOST") ?? "redis"
135+
},
129136
runnerIds: { Environment.decode("RUNNER_IDS", as: [String].self) ?? [] },
130137
shouldFail: { failureMode in
131138
let shouldFail = Environment.decode("FAILURE_MODE", as: [String: Double].self) ?? [:]

Sources/App/Core/Dependencies/RedisClient.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,14 @@ private actor Redis {
109109
}
110110

111111
private init() async throws {
112+
@Dependency(\.environment) var environment
112113
let connection = RedisConnection.make(
113-
configuration: try .init(hostname: Redis.hostname),
114+
configuration: try .init(hostname: environment.redisHostname()),
114115
boundEventLoop: NIOSingletons.posixEventLoopGroup.any()
115116
)
116117
self.client = try await connection.get()
117118
}
118119

119-
// This hostname has to match the redir service name in app.yml.
120-
static let hostname = "redis"
121120
static let maxConnectionAttempts = 3
122121

123122
func set(key: String, value: String?, expiresIn: Duration?) async {

0 commit comments

Comments
 (0)