feat: Renaming and moves some items around, listeners now manage reconnection events.
All checks were successful
CI / Run Tests (push) Successful in 4m16s
All checks were successful
CI / Run Tests (push) Successful in 4m16s
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import Dependencies
|
||||
import Logging
|
||||
import Models
|
||||
import MQTTConnectionManager
|
||||
import MQTTManager
|
||||
import ServiceLifecycle
|
||||
|
||||
public actor MQTTConnectionService: Service {
|
||||
@Dependency(\.mqttConnectionManager) var manager
|
||||
public struct MQTTConnectionService: Service {
|
||||
@Dependency(\.mqtt) var mqtt
|
||||
|
||||
private nonisolated let logger: Logger?
|
||||
private let logger: Logger?
|
||||
|
||||
public init(
|
||||
logger: Logger? = nil
|
||||
@@ -20,8 +20,8 @@ public actor MQTTConnectionService: Service {
|
||||
/// connection.
|
||||
public func run() async throws {
|
||||
try await withGracefulShutdownHandler {
|
||||
try await manager.connect()
|
||||
for await event in try manager.stream().cancelOnGracefulShutdown() {
|
||||
try await mqtt.connect()
|
||||
for await event in try mqtt.connectionStream().cancelOnGracefulShutdown() {
|
||||
// We don't really need to do anything with the events, so just logging
|
||||
// for now. But we need to iterate on an async stream for the service to
|
||||
// continue to run and handle graceful shutdowns.
|
||||
@@ -29,7 +29,7 @@ public actor MQTTConnectionService: Service {
|
||||
}
|
||||
// when we reach here we are shutting down, so we shutdown
|
||||
// the manager.
|
||||
manager.shutdown()
|
||||
mqtt.shutdown()
|
||||
} onGracefulShutdown: {
|
||||
self.logger?.trace("Received graceful shutdown.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user