Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added syncer types to heartbeat to know the github/bitbucket split #232

Merged
merged 1 commit into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

24 changes: 18 additions & 6 deletions BuildaHeartbeatKit/Heartbeat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -92,6 +104,6 @@ public protocol HeartbeatManagerDelegate {
}

private func stopSendingHeartbeat() {
timer?.invalidate()
self.timer?.invalidate()
}
}
10 changes: 8 additions & 2 deletions BuildaKit/SyncerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
6 changes: 2 additions & 4 deletions Buildasaur/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,8 +42,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
#else
self.setup()
#endif


}

func setup() {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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`)
Expand All @@ -60,7 +60,7 @@ SPEC CHECKSUMS:
Crashlytics: e4e8d02914f2608fbc7bf42b1a7af838b0db67a2
CryptoSwift: d382228d6301c09474132417878a741c2a2e68cd
DVR: 05cb292d3f71608e0a35afa85d475cbb56e37132
ekgclient: 40f5d347e2ede450b3e50ac7c6bd84d96e7b84ad
ekgclient: b9b0bddb882e281ced9178ead22e796619a9e9e2
Fabric: ed41fd62173c6bdea24ab02c9d7707161eabb750
Ji: ddebb22f9ac445db6e884b66f78ea74fb135fdb7
KeychainAccess: 9b7e49e48277e329b1b3195e54697ed313d30acf
Expand All @@ -73,6 +73,6 @@ SPEC CHECKSUMS:
SwiftSafe: 77ffd12b02678790bec1ef56a2d14ec5036f1fd6
XcodeServerSDK: 6300badc4a799da9ad6e970b366eda18d4a47bda

PODFILE CHECKSUM: 4a1e726dfe42c9b15fba7e59098eaabfebe21cc8
PODFILE CHECKSUM: 719a0c9e06ae8dea3e42db2d1c92a2218365900c

COCOAPODS: 1.0.0.beta.3