From 7baa36b4f213967618de8e6d5d07def414b55a9e Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Thu, 4 Feb 2016 14:56:59 +0000 Subject: [PATCH] Added syncer types to heartbeat to know the github/bitbucket split --- .travis.yml | 3 --- BuildaHeartbeatKit/Heartbeat.swift | 24 ++++++++++++++++++------ BuildaKit/SyncerManager.swift | 10 ++++++++-- Buildasaur/AppDelegate.swift | 6 ++---- Podfile | 2 +- Podfile.lock | 8 ++++---- 6 files changed, 33 insertions(+), 20 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1a6f4bf..0000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: objective-c -xcode_workspace: Buildasaur.xcworkspace -xcode_scheme: Buildasaur diff --git a/BuildaHeartbeatKit/Heartbeat.swift b/BuildaHeartbeatKit/Heartbeat.swift index c97e648..2c0fde6 100644 --- a/BuildaHeartbeatKit/Heartbeat.swift +++ b/BuildaHeartbeatKit/Heartbeat.swift @@ -11,7 +11,7 @@ import ekgclient import BuildaUtils public protocol HeartbeatManagerDelegate { - func numberOfRunningSyncers() -> Int + func typesOfRunningSyncers() -> [String: Int] } //READ: https://github.com/czechboy0/Buildasaur/tree/master#heartpulse-heartbeat @@ -22,6 +22,7 @@ public protocol HeartbeatManagerDelegate { private let client: EkgClient private let creationTime: Double private var timer: NSTimer? + private var initialTimer: NSTimer? private let interval: Double = 24 * 60 * 60 //send heartbeat once in 24 hours public init(server: String) { @@ -69,18 +70,29 @@ public protocol HeartbeatManagerDelegate { private func sendHeartbeatEvent() { let uptime = NSDate().timeIntervalSince1970 - self.creationTime - let numberOfRunningSyncers = self.delegate?.numberOfRunningSyncers() ?? 0 - self.sendEvent(HeartbeatEvent(uptime: uptime, numberOfRunningSyncers: numberOfRunningSyncers)) + let typesOfRunningSyncers = self.delegate?.typesOfRunningSyncers() ?? [:] + self.sendEvent(HeartbeatEvent(uptime: uptime, typesOfRunningSyncers: typesOfRunningSyncers)) } func _timerFired(timer: NSTimer?=nil) { self.sendHeartbeatEvent() + + if let initialTimer = self.initialTimer where initialTimer.valid { + initialTimer.invalidate() + self.initialTimer = nil + } } private func startSendingHeartbeat() { - //send once now - self._timerFired() + //send once in 10 seconds to give builda a chance to init and start + self.initialTimer?.invalidate() + self.initialTimer = NSTimer.scheduledTimerWithTimeInterval( + 20, + target: self, + selector: "_timerFired:", + userInfo: nil, + repeats: false) self.timer?.invalidate() self.timer = NSTimer.scheduledTimerWithTimeInterval( @@ -92,6 +104,6 @@ public protocol HeartbeatManagerDelegate { } private func stopSendingHeartbeat() { - timer?.invalidate() + self.timer?.invalidate() } } diff --git a/BuildaKit/SyncerManager.swift b/BuildaKit/SyncerManager.swift index 7ae5799..4a7c24f 100644 --- a/BuildaKit/SyncerManager.swift +++ b/BuildaKit/SyncerManager.swift @@ -111,7 +111,13 @@ public class SyncerManager { } extension SyncerManager: HeartbeatManagerDelegate { - public func numberOfRunningSyncers() -> Int { - return self.syncers.filter { $0.active }.count + + public func typesOfRunningSyncers() -> [String : Int] { + return self.syncers.filter { $0.active }.reduce([:]) { (all, syncer) -> [String: Int] in + var stats = all + let syncerType = syncer._project.workspaceMetadata!.service.rawValue + stats[syncerType] = (stats[syncerType] ?? 0) + 1 + return stats + } } } diff --git a/Buildasaur/AppDelegate.swift b/Buildasaur/AppDelegate.swift index 7204a6d..2c74f47 100644 --- a/Buildasaur/AppDelegate.swift +++ b/Buildasaur/AppDelegate.swift @@ -11,7 +11,7 @@ import Cocoa /* Please report any crashes on GitHub, I may optionally ask you to email them to me. Thanks! You can find them at ~/Library/Logs/DiagnosticReports/Buildasaur-* -Also, you can find the log at ~/Library/Application Support/Buildasaur/Builda.log +Also, you can find the logs at ~/Library/Application Support/Buildasaur/Logs */ import BuildaUtils @@ -42,8 +42,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { #else self.setup() #endif - - } func setup() { @@ -110,7 +108,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let syncerManager = SyncerManager(storageManager: storageManager, factory: factory, loginItem: loginItem) self.syncerManager = syncerManager - if let heartbeatOptOut = storageManager.config.value["crash_reporting_opt_out"] as? Bool where heartbeatOptOut { + if let crashlyticsOptOut = storageManager.config.value["crash_reporting_opt_out"] as? Bool where crashlyticsOptOut { Log.info("User opted out of crash reporting") } else { #if DEBUG diff --git a/Podfile b/Podfile index 119c4f7..a3f762d 100644 --- a/Podfile +++ b/Podfile @@ -26,7 +26,7 @@ end def also_xcode_pods pods_for_errbody pod 'XcodeServerSDK', '~> 0.5.6' - pod 'ekgclient', '~> 0.3.0' + pod 'ekgclient', '~> 0.3.1' end def buildasaur_app_pods diff --git a/Podfile.lock b/Podfile.lock index 44fbde9..6fc20f8 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -6,7 +6,7 @@ PODS: - Fabric (~> 1.6.3) - CryptoSwift (0.2.2) - DVR (0.2.1-snap1) - - ekgclient (0.3.0): + - ekgclient (0.3.1): - Alamofire (= 2.0.0-beta.3) - Fabric (1.6.4) - Ji (1.2.0): @@ -40,7 +40,7 @@ DEPENDENCIES: - Crashlytics - CryptoSwift - DVR (~> 0.2.1-snap1) - - ekgclient (~> 0.3.0) + - ekgclient (~> 0.3.1) - Ji (~> 1.2.0) - KeychainAccess - Keys (from `Pods/CocoaPodsKeys`) @@ -60,7 +60,7 @@ SPEC CHECKSUMS: Crashlytics: e4e8d02914f2608fbc7bf42b1a7af838b0db67a2 CryptoSwift: d382228d6301c09474132417878a741c2a2e68cd DVR: 05cb292d3f71608e0a35afa85d475cbb56e37132 - ekgclient: 40f5d347e2ede450b3e50ac7c6bd84d96e7b84ad + ekgclient: b9b0bddb882e281ced9178ead22e796619a9e9e2 Fabric: ed41fd62173c6bdea24ab02c9d7707161eabb750 Ji: ddebb22f9ac445db6e884b66f78ea74fb135fdb7 KeychainAccess: 9b7e49e48277e329b1b3195e54697ed313d30acf @@ -73,6 +73,6 @@ SPEC CHECKSUMS: SwiftSafe: 77ffd12b02678790bec1ef56a2d14ec5036f1fd6 XcodeServerSDK: 6300badc4a799da9ad6e970b366eda18d4a47bda -PODFILE CHECKSUM: 4a1e726dfe42c9b15fba7e59098eaabfebe21cc8 +PODFILE CHECKSUM: 719a0c9e06ae8dea3e42db2d1c92a2218365900c COCOAPODS: 1.0.0.beta.3