Skip to content

Commit 7889c55

Browse files
Analytics fixes (#3110)
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 4a7371a commit 7889c55

17 files changed

+57
-100
lines changed

lib/bootstrap.ts

-1
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

-6
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

-24
This file was deleted.

lib/lockfile.ts

-31
This file was deleted.

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

+2
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

+25-22
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

+11-2
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

+7-2
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

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"ios-device-lib": "0.4.9",
4848
"ios-mobileprovision-finder": "1.0.10",
4949
"ios-sim-portable": "3.1.1",
50-
"lockfile": "1.0.1",
50+
"lockfile": "1.0.3",
5151
"lodash": "4.13.1",
5252
"log4js": "1.0.1",
5353
"marked": "0.3.6",
@@ -87,6 +87,7 @@
8787
"@types/chai": "4.0.1",
8888
"@types/chai-as-promised": "0.0.31",
8989
"@types/chokidar": "1.6.0",
90+
"@types/lockfile": "1.0.0",
9091
"@types/node": "6.0.61",
9192
"@types/qr-image": "3.2.0",
9293
"@types/request": "0.0.45",

test/npm-installation-manager.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function createTestInjector(): IInjector {
1515

1616
testInjector.register("config", ConfigLib.Configuration);
1717
testInjector.register("logger", LoggerLib.Logger);
18-
testInjector.register("lockfile", {});
1918
testInjector.register("errors", ErrorsLib.Errors);
2019
testInjector.register("options", OptionsLib.Options);
2120
testInjector.register("fs", FsLib.FileSystem);

test/npm-support.ts

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { ProjectFilesProvider } from "../lib/providers/project-files-provider";
2323
import { MobilePlatformsCapabilities } from "../lib/mobile-platforms-capabilities";
2424
import { DevicePlatformsConstants } from "../lib/common/mobile/device-platforms-constants";
2525
import { XmlValidator } from "../lib/xml-validator";
26-
import { LockFile } from "../lib/lockfile";
2726
import ProjectChangesLib = require("../lib/services/project-changes-service");
2827
import { Messages } from "../lib/common/messages/messages";
2928
import { NodeModulesDependenciesBuilder } from "../lib/tools/node-modules/node-modules-dependencies-builder";
@@ -48,7 +47,6 @@ function createTestInjector(): IInjector {
4847
testInjector.register("platformService", PlatformServiceLib.PlatformService);
4948
testInjector.register("logger", stubs.LoggerStub);
5049
testInjector.register("npmInstallationManager", {});
51-
testInjector.register("lockfile", LockFile);
5250
testInjector.register("prompter", {});
5351
testInjector.register("sysInfo", {});
5452
testInjector.register("androidProjectService", {});

test/platform-commands.ts

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ function createTestInjector() {
112112
testInjector.registerCommand("platform|remove", PlatformRemoveCommandLib.RemovePlatformCommand);
113113
testInjector.registerCommand("platform|update", PlatformUpdateCommandLib.UpdatePlatformCommand);
114114
testInjector.registerCommand("platform|clean", PlatformCleanCommandLib.CleanCommand);
115-
testInjector.register("lockfile", {});
116115
testInjector.register("resources", {});
117116
testInjector.register("commandsServiceProvider", {
118117
registerDynamicSubCommands: () => { /* intentionally left blank */ }

test/platform-service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function createTestInjector() {
3939
testInjector.register('projectDataService', stubs.ProjectDataService);
4040
testInjector.register('prompter', {});
4141
testInjector.register('sysInfo', {});
42-
testInjector.register('lockfile', stubs.LockFile);
4342
testInjector.register("commandsService", {
4443
tryExecuteCommand: () => { /* intentionally left blank */ }
4544
});

test/plugins-service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ function createTestInjector() {
6969
registerDynamicSubCommands: () => { /* intentionally empty body */ }
7070
});
7171
testInjector.register("hostInfo", HostInfo);
72-
testInjector.register("lockfile", {});
7372
testInjector.register("projectHelper", ProjectHelper);
7473

7574
testInjector.register("pluginsService", PluginsService);

test/project-service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ class ProjectIntegrationTest {
145145
this.testInjector.register("npmInstallationManager", NpmInstallationManager);
146146
this.testInjector.register("npm", NpmLib.NodePackageManager);
147147
this.testInjector.register("httpClient", HttpClientLib.HttpClient);
148-
this.testInjector.register("lockfile", stubs.LockFile);
149148

150149
this.testInjector.register("options", Options);
151150
this.testInjector.register("hostInfo", HostInfo);

0 commit comments

Comments
 (0)