Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.development.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ DATABASE_PORT=6432
DATABASE_NAME=spi_dev
DATABASE_USERNAME=spi_dev
DATABASE_PASSWORD=xxx
REDIS_HOST=localhost
1 change: 1 addition & 0 deletions .env.testing.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ DATABASE_PORT=5432
DATABASE_NAME=spi_test
DATABASE_USERNAME=spi_test
DATABASE_PASSWORD=xxx
REDIS_HOST=localhost
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ ingest:
analyze:
swift run Run analyze --limit 1

db-up: db-up-dev db-up-test
redis-up-dev:
docker run --name spi_redis -p 6379:6379 -d redis/redis-stack:7.4.0-v1

redis-down-dev:
docker rm -f spi_redis

db-up: db-up-dev db-up-test redis-up-dev

db-up-dev:
docker run --name spi_dev -e POSTGRES_DB=spi_dev -e POSTGRES_USER=spi_dev -e POSTGRES_PASSWORD=xxx -p 6432:5432 -d postgres:16-alpine
Expand All @@ -111,7 +117,7 @@ db-up-test:
-d \
postgres:13-alpine

db-down: db-down-dev db-down-test
db-down: db-down-dev db-down-test redis-down-dev

db-down-dev:
docker rm -f spi_dev
Expand Down
9 changes: 8 additions & 1 deletion Sources/App/Core/Dependencies/EnvironmentClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct EnvironmentClient {
var plausibleBackendReportingSiteID: @Sendable () -> String?
var processingBuildBacklog: @Sendable () -> Bool = { XCTFail("processingBuildBacklog"); return false }
var random: @Sendable (_ range: ClosedRange<Double>) -> Double = { XCTFail("random"); return Double.random(in: $0) }
var runnerIds: @Sendable () -> [String] = { XCTFail("runnerIds"); return [] }

enum FailureMode: String {
case fetchMetadataFailed
Expand All @@ -59,6 +58,8 @@ struct EnvironmentClient {
case repositorySaveFailed
case repositorySaveUniqueViolation
}
var redisHostname: @Sendable () -> String = { "redis" }
var runnerIds: @Sendable () -> [String] = { XCTFail("runnerIds"); return [] }
var shouldFail: @Sendable (_ failureMode: FailureMode) -> Bool = { _ in XCTFail("shouldFail"); return false }
var siteURL: @Sendable () -> String = { XCTFail("siteURL"); return "" }
}
Expand Down Expand Up @@ -126,6 +127,12 @@ extension EnvironmentClient: DependencyKey {
Environment.get("PROCESSING_BUILD_BACKLOG").flatMap(\.asBool) ?? false
},
random: { range in Double.random(in: range) },
redisHostname: {
// Defaulting this to `redis`, which is the service name in `app.yml`.
// This is also why `REDIS_HOST` is not set as an env variable in `app.yml`,
// it's a known value that needs no configuration outside of local use for testing.
Environment.get("REDIS_HOST") ?? "redis"
},
runnerIds: { Environment.decode("RUNNER_IDS", as: [String].self) ?? [] },
shouldFail: { failureMode in
let shouldFail = Environment.decode("FAILURE_MODE", as: [String: Double].self) ?? [:]
Expand Down
5 changes: 2 additions & 3 deletions Sources/App/Core/Dependencies/RedisClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ private actor Redis {
}

private init() async throws {
@Dependency(\.environment) var environment
let connection = RedisConnection.make(
configuration: try .init(hostname: Redis.hostname),
configuration: try .init(hostname: environment.redisHostname()),
boundEventLoop: NIOSingletons.posixEventLoopGroup.any()
)
self.client = try await connection.get()
}

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

func set(key: String, value: String?, expiresIn: Duration?) async {
Expand Down
Loading