Skip to content

Commit fe8ed97

Browse files
Analytics fixes
Move lockfile service to common and lock operation for writing user settings file Add new lockfile service (use lockfile npm package) and lock all operations for reading/writing user-settings.json. These operations may be executed in different processes, so they must be synced between them. Clean obsolete code for lockfile in services that do not longer use it. Ensure failures in eqatec analytics will not prevent tracking in google analytics by try-catching execution in broker service.
1 parent 3774db5 commit fe8ed97

17 files changed

+57
-100
lines changed

lib/bootstrap.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ $injector.require("itmsTransporterService", "./services/itmstransporter-service"
7171

7272
$injector.requirePublic("npm", "./node-package-manager");
7373
$injector.require("npmInstallationManager", "./npm-installation-manager");
74-
$injector.require("lockfile", "./lockfile");
7574
$injector.require("dynamicHelpProvider", "./dynamic-help-provider");
7675
$injector.require("mobilePlatformsCapabilities", "./mobile-platforms-capabilities");
7776
$injector.require("commandsServiceProvider", "./providers/commands-service-provider");

lib/declarations.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,6 @@ interface IApplicationPackage {
318318
time: Date;
319319
}
320320

321-
interface ILockFile {
322-
lock(): void;
323-
unlock(): void;
324-
check(): boolean;
325-
}
326-
327321
interface IOpener {
328322
open(target: string, appname: string): void;
329323
}

lib/definitions/lockfile.d.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

lib/lockfile.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

lib/services/analytics/analytics-broker-process.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// NOTE: This file is used to track data in a separate process.
2+
// The instances here are not shared with the ones in main CLI process.
13
import * as fs from "fs";
24
import { AnalyticsBroker } from "./analytics-broker";
35

lib/services/analytics/analytics-broker.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,32 @@ export class AnalyticsBroker implements IAnalyticsBroker {
1717
private $injector: IInjector) { }
1818

1919
public async sendDataForTracking(trackInfo: ITrackingInformation): Promise<void> {
20-
const eqatecProvider = await this.getEqatecAnalyticsProvider();
21-
const googleProvider = await this.getGoogleAnalyticsProvider();
22-
23-
switch (trackInfo.type) {
24-
case TrackingTypes.Exception:
25-
await eqatecProvider.trackError(<IExceptionsTrackingInformation>trackInfo);
26-
break;
27-
case TrackingTypes.Feature:
28-
await eqatecProvider.trackInformation(<IFeatureTrackingInformation>trackInfo);
29-
break;
30-
case TrackingTypes.AcceptTrackFeatureUsage:
31-
await eqatecProvider.acceptFeatureUsageTracking(<IAcceptUsageReportingInformation>trackInfo);
32-
break;
33-
case TrackingTypes.GoogleAnalyticsData:
34-
await googleProvider.trackHit(<IGoogleAnalyticsTrackingInformation>trackInfo);
35-
break;
36-
case TrackingTypes.Finish:
37-
await eqatecProvider.finishTracking();
38-
break;
39-
default:
40-
throw new Error(`Invalid tracking type: ${trackInfo.type}`);
20+
try {
21+
const eqatecProvider = await this.getEqatecAnalyticsProvider();
22+
const googleProvider = await this.getGoogleAnalyticsProvider();
23+
24+
switch (trackInfo.type) {
25+
case TrackingTypes.Exception:
26+
await eqatecProvider.trackError(<IExceptionsTrackingInformation>trackInfo);
27+
break;
28+
case TrackingTypes.Feature:
29+
await eqatecProvider.trackInformation(<IFeatureTrackingInformation>trackInfo);
30+
break;
31+
case TrackingTypes.AcceptTrackFeatureUsage:
32+
await eqatecProvider.acceptFeatureUsageTracking(<IAcceptUsageReportingInformation>trackInfo);
33+
break;
34+
case TrackingTypes.GoogleAnalyticsData:
35+
await googleProvider.trackHit(<IGoogleAnalyticsTrackingInformation>trackInfo);
36+
break;
37+
case TrackingTypes.Finish:
38+
await eqatecProvider.finishTracking();
39+
break;
40+
default:
41+
throw new Error(`Invalid tracking type: ${trackInfo.type}`);
42+
}
43+
} catch (err) {
44+
// So, lets ignore the error for now until we find out what to do with it.
4145
}
42-
4346
}
4447

4548
}

lib/services/analytics/analytics-service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ export class AnalyticsService extends AnalyticsServiceBase {
6565
public async trackEventActionInGoogleAnalytics(data: IEventActionData): Promise<void> {
6666
const device = data.device;
6767
const platform = device ? device.deviceInfo.platform : data.platform;
68+
const normalizedPlatform = platform ? this.$mobileHelper.normalizePlatformName(platform) : platform;
6869
const isForDevice = device ? !device.isEmulator : data.isForDevice;
6970

7071
let label: string = "";
71-
label = this.addDataToLabel(label, platform);
72+
label = this.addDataToLabel(label, normalizedPlatform);
7273

7374
// In some cases (like in case action is Build and platform is Android), we do not know if the deviceType is emulator or device.
7475
// Just exclude the device_type in this case.
@@ -182,7 +183,15 @@ export class AnalyticsService extends AnalyticsServiceBase {
182183

183184
private async sendMessageToBroker(message: ITrackingInformation): Promise<void> {
184185
const broker = await this.getAnalyticsBroker();
185-
return new Promise<void>((resolve, reject) => broker.send(message, resolve));
186+
return new Promise<void>((resolve, reject) => {
187+
if (broker && broker.connected) {
188+
try {
189+
broker.send(message, resolve);
190+
} catch (err) {
191+
this.$logger.trace("Error while trying to send message to broker:", err);
192+
}
193+
}
194+
});
186195
}
187196
}
188197

lib/services/user-settings-service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import * as userSettingsServiceBaseLib from "../common/services/user-settings-se
33

44
class UserSettingsService extends userSettingsServiceBaseLib.UserSettingsServiceBase {
55
constructor($fs: IFileSystem,
6-
$options: IOptions) {
6+
$options: IOptions,
7+
$lockfile: ILockFile) {
78
const userSettingsFilePath = path.join($options.profileDir, "user-settings.json");
8-
super(userSettingsFilePath, $fs);
9+
super(userSettingsFilePath, $fs, $lockfile);
10+
}
11+
12+
public async loadUserSettingsFile(): Promise<void> {
13+
await this.loadUserSettingsData();
914
}
1015
}
1116
$injector.register("userSettingsService", UserSettingsService);

npm-shrinkwrap.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)