Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions Sources/App/Core/Dependencies/EnvironmentClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
case repositorySaveFailed
case repositorySaveUniqueViolation
}
var redisHostname: @Sendable () -> String = { "redis" }
var shouldFail: @Sendable (_ failureMode: FailureMode) -> Bool = { _ in XCTFail("shouldFail"); return false }
var siteURL: @Sendable () -> String = { XCTFail("siteURL"); return "" }
}
Expand Down Expand Up @@ -126,7 +127,13 @@
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) ?? [] },

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'

Check failure on line 136 in Sources/App/Core/Dependencies/EnvironmentClient.swift

View workflow job for this annotation

GitHub Actions / Test

argument 'runnerIds' must precede argument 'redisHostname'
shouldFail: { failureMode in
let shouldFail = Environment.decode("FAILURE_MODE", as: [String: Double].self) ?? [:]
guard let rate = shouldFail[failureMode.rawValue] else { return false }
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