Skip to content

Commit

Permalink
fixed heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
czechboy0 committed Oct 13, 2015
1 parent 2a29ab2 commit 6dd63dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
22 changes: 0 additions & 22 deletions BuildaKit/StorageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Foundation
import BuildaGitServer
import BuildaUtils
import XcodeServerSDK
import BuildaHeartbeatKit
import ReactiveCocoa

public enum StorageManagerError: ErrorType {
Expand All @@ -27,31 +26,18 @@ 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()
}

deinit {
//
}

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)
}
Expand Down Expand Up @@ -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
}
}
24 changes: 23 additions & 1 deletion BuildaKit/SyncerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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
}
}

0 comments on commit 6dd63dc

Please sign in to comment.