From 6dd63dc64f4e27ba6a55cd9ad2e34933d6bcc151 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 13 Oct 2015 20:28:04 +0100 Subject: [PATCH] fixed heartbeat --- BuildaKit/StorageManager.swift | 22 ---------------------- BuildaKit/SyncerManager.swift | 24 +++++++++++++++++++++++- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/BuildaKit/StorageManager.swift b/BuildaKit/StorageManager.swift index 10cc035..b3c6dc6 100644 --- a/BuildaKit/StorageManager.swift +++ b/BuildaKit/StorageManager.swift @@ -10,7 +10,6 @@ import Foundation import BuildaGitServer import BuildaUtils import XcodeServerSDK -import BuildaHeartbeatKit import ReactiveCocoa public enum StorageManagerError: ErrorType { @@ -27,13 +26,11 @@ public class StorageManager { public let triggerConfigs = MutableProperty<[String: TriggerConfig]>([:]) public let config = MutableProperty<[String: AnyObject]>([:]) - private var heartbeatManager: HeartbeatManager! private let persistence: Persistence public init(persistence: Persistence) { self.persistence = persistence self.loadAllFromPersistence() - self.setupHeartbeatManager() self.setupSaving() } @@ -41,17 +38,6 @@ public class StorageManager { // } - private func setupHeartbeatManager() { - if let heartbeatOptOut = self.config.value["heartbeat_opt_out"] as? Bool where heartbeatOptOut { - Log.info("User opted out of anonymous heartbeat") - } else { - Log.info("Will send anonymous heartbeat. To opt out add `\"heartbeat_opt_out\" = true` to ~/Library/Application Support/Buildasaur/Config.json") - self.heartbeatManager = HeartbeatManager(server: "https://builda-ekg.herokuapp.com") - self.heartbeatManager.delegate = self - self.heartbeatManager.start() - } - } - public func checkForProjectOrWorkspace(url: NSURL) throws { _ = try Project.attemptToParseFromUrl(url) } @@ -281,11 +267,3 @@ extension StorageManager { return nil } } - -extension StorageManager: HeartbeatManagerDelegate { - public func numberOfRunningSyncers() -> Int { - //TODO: move this so the SyncerManager - return -1 -// return self.syncerConfigs.value.filter { $0.active }.count - } -} diff --git a/BuildaKit/SyncerManager.swift b/BuildaKit/SyncerManager.swift index e09c541..72b0557 100644 --- a/BuildaKit/SyncerManager.swift +++ b/BuildaKit/SyncerManager.swift @@ -9,6 +9,8 @@ import Foundation import ReactiveCocoa import XcodeServerSDK +import BuildaHeartbeatKit +import BuildaUtils //owns running syncers and their children, manages starting/stopping them, //creating them from configurations @@ -27,10 +29,12 @@ public class SyncerManager { public var syncers: [HDGitHubXCBotSyncer] private var configTriplets: SignalProducer<[ConfigTriplet], NoError> - + private var heartbeatManager: HeartbeatManager! + public init(storageManager: StorageManager, factory: SyncerFactoryType) { self.storageManager = storageManager + self.factory = factory self.syncers = [] let configTriplets = SyncerProducerFactory.createTripletsProducer(storageManager) @@ -51,6 +55,18 @@ public class SyncerManager { syncersProducer.startWithNext { [weak self] in self?.syncers = $0 } self.checkForAutostart() + self.setupHeartbeatManager() + } + + private func setupHeartbeatManager() { + if let heartbeatOptOut = self.storageManager.config.value["heartbeat_opt_out"] as? Bool where heartbeatOptOut { + Log.info("User opted out of anonymous heartbeat") + } else { + Log.info("Will send anonymous heartbeat. To opt out add `\"heartbeat_opt_out\" = true` to ~/Library/Application Support/Buildasaur/Config.json") + self.heartbeatManager = HeartbeatManager(server: "https://builda-ekg.herokuapp.com") + self.heartbeatManager.delegate = self + self.heartbeatManager.start() + } } private func checkForAutostart() { @@ -91,3 +107,9 @@ public class SyncerManager { self.syncers.forEach { $0.active = false } } } + +extension SyncerManager: HeartbeatManagerDelegate { + public func numberOfRunningSyncers() -> Int { + return self.syncers.filter { $0.active }.count + } +}