Skip to content

Commit 1b8a954

Browse files
chore: rename interfaces for cleanup
Improve interfaces and enums for cleanup services.
1 parent 5744075 commit 1b8a954

8 files changed

+61
-60
lines changed

lib/common/mobile/mobile-core/android-process-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class AndroidProcessService implements Mobile.IAndroidProcessService {
122122
}
123123

124124
this._forwardedLocalPorts[portForwardInputData.deviceIdentifier] = localPort;
125-
await this.$cleanupService.addCleanupAction({ command: await this.$staticConfig.getAdbFilePath(), args: ["-s", portForwardInputData.deviceIdentifier, "forward", "--remove", `tcp:${localPort}`] });
125+
await this.$cleanupService.addCleanupCommand({ command: await this.$staticConfig.getAdbFilePath(), args: ["-s", portForwardInputData.deviceIdentifier, "forward", "--remove", `tcp:${localPort}`] });
126126
return localPort && +localPort;
127127
}
128128

lib/definitions/cleanup-service.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
interface ICleanupService extends IShouldDispose, IDisposable {
66
/**
77
* Add new action to be executed when CLI process exits.
8-
* @param {ICleanupAction} action The action that should be executed, including command and args.
8+
* @param {ISpawnCommandInfo} commandInfo The command that should be executed, including command and args.
99
* @returns {Promise<void>}
1010
*/
11-
addCleanupAction(action: ICleanupAction): Promise<void>;
11+
addCleanupCommand(commandInfo: ISpawnCommandInfo): Promise<void>;
1212

1313
/**
1414
* Remove action to be executed when CLI process exits.
1515
* NOTE: The action should be added in the action list by calling `addCleanupAction` first.
16-
* @param {ICleanupAction} action The action that should be removed from cleanup execution, including command and args.
16+
* @param {ISpawnCommandInfo} commandInfo The command that should be removed from cleanup execution, including command and args.
1717
* @returns {Promise<void>}
1818
*/
19-
removeCleanupAction(action: ICleanupAction): Promise<void>
19+
removeCleanupCommand(commandInfo: ISpawnCommandInfo): Promise<void>
2020

2121
/**
2222
* Sets the file in which the cleanup process will write its logs.

lib/detached-processes/cleanup-process-definitions.d.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
interface ICleanupAction {
1+
interface ISpawnCommandInfo {
22
/**
33
* Executable to be started.
44
*/
@@ -8,27 +8,28 @@ interface ICleanupAction {
88
* Arguments that will be passed to the child process
99
*/
1010
args: string[];
11+
1112
/**
1213
* Timeout to execute the action.
1314
*/
1415
timeout?: number;
1516
}
1617

17-
interface ICleanupProcessMessage {
18+
interface ICleanupMessageBase {
1819
/**
19-
* Type of the action
20+
* Type of the message
2021
*/
21-
actionType: CleanupProcessMessageType;
22+
messageType: CleanupProcessMessage;
2223
}
2324

24-
interface ICleanupActionMessage extends ICleanupProcessMessage {
25+
interface ISpawnCommandCleanupMessage extends ICleanupMessageBase {
2526
/**
26-
* Describes the action that must be executed
27+
* Describes the command that must be executed
2728
*/
28-
action: ICleanupAction;
29+
commandInfo: ISpawnCommandInfo;
2930
}
3031

31-
interface ICleanupDeleteActionMessage extends ICleanupProcessMessage {
32+
interface IDeleteFileCleanupMessage extends ICleanupMessageBase {
3233
/**
3334
* Path to file/directory to be deleted.
3435
*/

lib/detached-processes/cleanup-process.ts

+27-27
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ require(pathToBootstrap);
1717
const fileLogService = $injector.resolve<IFileLogService>(FileLogService, { logFile });
1818
fileLogService.logData({ message: "Initializing Cleanup process." });
1919

20-
const actionsToExecute: ICleanupAction[] = [];
20+
const commandsInfos: ISpawnCommandInfo[] = [];
2121
const filesToDelete: string[] = [];
2222

2323
const executeCleanup = async () => {
2424
const $childProcess = $injector.resolve<IChildProcess>("childProcess");
25-
for (const action of actionsToExecute) {
25+
for (const commandInfo of commandsInfos) {
2626
try {
27-
fileLogService.logData({ message: `Start executing action: ${JSON.stringify(action)}` });
27+
fileLogService.logData({ message: `Start executing command: ${JSON.stringify(commandInfo)}` });
2828

29-
await $childProcess.trySpawnFromCloseEvent(action.command, action.args, {}, { throwError: true, timeout: action.timeout || 3000 });
30-
fileLogService.logData({ message: `Successfully executed action: ${JSON.stringify(action)}` });
29+
await $childProcess.trySpawnFromCloseEvent(commandInfo.command, commandInfo.args, {}, { throwError: true, timeout: commandInfo.timeout || 3000 });
30+
fileLogService.logData({ message: `Successfully executed command: ${JSON.stringify(commandInfo)}` });
3131
} catch (err) {
32-
fileLogService.logData({ message: `Unable to execute action: ${JSON.stringify(action)}`, type: FileLogMessageType.Error });
32+
fileLogService.logData({ message: `Unable to execute command: ${JSON.stringify(commandInfo)}`, type: FileLogMessageType.Error });
3333
}
3434
}
3535

@@ -42,21 +42,21 @@ const executeCleanup = async () => {
4242
process.exit();
4343
};
4444

45-
const addCleanupAction = (newAction: ICleanupAction): void => {
46-
if (_.some(actionsToExecute, currentAction => _.isEqual(currentAction, newAction))) {
47-
fileLogService.logData({ message: `cleanup-process will not add action for execution as it has been added already: ${JSON.stringify(newAction)}` });
45+
const addCleanupAction = (commandInfo: ISpawnCommandInfo): void => {
46+
if (_.some(commandsInfos, currentCommandInfo => _.isEqual(currentCommandInfo, commandInfo))) {
47+
fileLogService.logData({ message: `cleanup-process will not add command for execution as it has been added already: ${JSON.stringify(commandInfo)}` });
4848
} else {
49-
fileLogService.logData({ message: `cleanup-process added action for execution: ${JSON.stringify(newAction)}` });
50-
actionsToExecute.push(newAction);
49+
fileLogService.logData({ message: `cleanup-process added command for execution: ${JSON.stringify(commandInfo)}` });
50+
commandsInfos.push(commandInfo);
5151
}
5252
};
5353

54-
const removeCleanupAction = (actionToRemove: ICleanupAction): void => {
55-
if (_.some(actionsToExecute, currentAction => _.isEqual(currentAction, actionToRemove))) {
56-
_.remove(actionsToExecute, currentAction => _.isEqual(currentAction, actionToRemove));
57-
fileLogService.logData({ message: `cleanup-process removed action for execution: ${JSON.stringify(actionToRemove)}` });
54+
const removeCleanupAction = (commandInfo: ISpawnCommandInfo): void => {
55+
if (_.some(commandsInfos, currentCommandInfo => _.isEqual(currentCommandInfo, commandInfo))) {
56+
_.remove(commandsInfos, currentCommandInfo => _.isEqual(currentCommandInfo, commandInfo));
57+
fileLogService.logData({ message: `cleanup-process removed command for execution: ${JSON.stringify(commandInfo)}` });
5858
} else {
59-
fileLogService.logData({ message: `cleanup-process cannot remove action for execution as it has note been added before: ${JSON.stringify(actionToRemove)}` });
59+
fileLogService.logData({ message: `cleanup-process cannot remove command for execution as it has note been added before: ${JSON.stringify(commandInfo)}` });
6060
}
6161
};
6262

@@ -82,24 +82,24 @@ const removeDeleteAction = (filePath: string): void => {
8282
}
8383
};
8484

85-
process.on("message", async (cleanupProcessMessage: ICleanupProcessMessage) => {
85+
process.on("message", async (cleanupProcessMessage: ICleanupMessageBase) => {
8686
fileLogService.logData({ message: `cleanup-process received message of type: ${JSON.stringify(cleanupProcessMessage)}` });
8787

88-
switch (cleanupProcessMessage.actionType) {
89-
case CleanupProcessMessageType.AddCleanAction:
90-
addCleanupAction((<ICleanupActionMessage>cleanupProcessMessage).action);
88+
switch (cleanupProcessMessage.messageType) {
89+
case CleanupProcessMessage.AddCleanCommand:
90+
addCleanupAction((<ISpawnCommandCleanupMessage>cleanupProcessMessage).commandInfo);
9191
break;
92-
case CleanupProcessMessageType.RemoveCleanAction:
93-
removeCleanupAction((<ICleanupActionMessage>cleanupProcessMessage).action);
92+
case CleanupProcessMessage.RemoveCleanCommand:
93+
removeCleanupAction((<ISpawnCommandCleanupMessage>cleanupProcessMessage).commandInfo);
9494
break;
95-
case CleanupProcessMessageType.AddDeleteAction:
96-
addDeleteAction((<ICleanupDeleteActionMessage>cleanupProcessMessage).filePath);
95+
case CleanupProcessMessage.AddDeleteFileAction:
96+
addDeleteAction((<IDeleteFileCleanupMessage>cleanupProcessMessage).filePath);
9797
break;
98-
case CleanupProcessMessageType.RemoveDeleteAction:
99-
removeDeleteAction((<ICleanupDeleteActionMessage>cleanupProcessMessage).filePath);
98+
case CleanupProcessMessage.RemoveDeleteFileAction:
99+
removeDeleteAction((<IDeleteFileCleanupMessage>cleanupProcessMessage).filePath);
100100
break;
101101
default:
102-
fileLogService.logData({ message: `Unable to handle message of type ${cleanupProcessMessage.actionType}. Full message is ${JSON.stringify(cleanupProcessMessage)}`, type: FileLogMessageType.Error });
102+
fileLogService.logData({ message: `Unable to handle message of type ${cleanupProcessMessage.messageType}. Full message is ${JSON.stringify(cleanupProcessMessage)}`, type: FileLogMessageType.Error });
103103
break;
104104
}
105105

lib/detached-processes/detached-process-enums.d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ declare const enum FileLogMessageType {
2323
Error = "Error"
2424
}
2525

26-
declare const enum CleanupProcessMessageType {
26+
declare const enum CleanupProcessMessage {
2727
/**
28-
* This type of action defines that cleanup procedure should execute specific action.
28+
* This type of message defines that cleanup procedure should execute specific command.
2929
*/
30-
AddCleanAction = "AddCleanAction",
30+
AddCleanCommand = "AddCleanCommand",
3131

3232
/**
33-
* This type of action defines that cleanup procedure should not execute previously defined cleanup action.
33+
* This type of message defines that cleanup procedure should not execute previously defined cleanup command.
3434
*/
35-
RemoveCleanAction = "RemoveCleanAction",
35+
RemoveCleanCommand = "RemoveCleanCommand",
3636

3737
/**
38-
* This type of action defines that cleanup procedure should delete specified files.
38+
* This type of message defines that cleanup procedure should delete specified files.
3939
*/
40-
AddDeleteAction = "AddDeleteAction",
40+
AddDeleteFileAction = "AddDeleteFileAction",
4141

4242
/**
43-
* This type of action defines the cleanup procedure should not delete previously specified file.
43+
* This type of message defines the cleanup procedure should not delete previously specified file.
4444
*/
45-
RemoveDeleteAction = "RemoveDeleteAction",
45+
RemoveDeleteFileAction = "RemoveDeleteFileAction",
4646

4747
}

lib/services/android-device-debug-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
7171
await this.unixSocketForward(port, `${unixSocketName}`);
7272
}
7373

74-
await this.$cleanupService.addCleanupAction({ command: await this.$staticConfig.getAdbFilePath(), args: ["-s", deviceId, "forward", "--remove", `tcp:${port}`] });
74+
await this.$cleanupService.addCleanupCommand({ command: await this.$staticConfig.getAdbFilePath(), args: ["-s", deviceId, "forward", "--remove", `tcp:${port}`] });
7575

7676
return port;
7777
}

lib/services/cleanup-service.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ export class CleanupService implements ICleanupService {
1515

1616
public shouldDispose = false;
1717

18-
public async addCleanupAction(action: ICleanupAction): Promise<void> {
18+
public async addCleanupCommand(commandInfo: ISpawnCommandInfo): Promise<void> {
1919
const cleanupProcess = await this.getCleanupProcess();
20-
cleanupProcess.send(<ICleanupProcessMessage>{ actionType: CleanupProcessMessageType.AddCleanAction, action });
20+
cleanupProcess.send(<ISpawnCommandCleanupMessage>{ messageType: CleanupProcessMessage.AddCleanCommand, commandInfo });
2121
}
2222

23-
public async removeCleanupAction(action: ICleanupAction): Promise<void> {
23+
public async removeCleanupCommand(commandInfo: ISpawnCommandInfo): Promise<void> {
2424
const cleanupProcess = await this.getCleanupProcess();
25-
cleanupProcess.send(<ICleanupProcessMessage>{ actionType: CleanupProcessMessageType.RemoveCleanAction, action });
25+
cleanupProcess.send(<ISpawnCommandCleanupMessage>{ messageType: CleanupProcessMessage.RemoveCleanCommand, commandInfo });
2626
}
2727

2828
public async addCleanupDeleteAction(filePath: string): Promise<void> {
2929
const cleanupProcess = await this.getCleanupProcess();
30-
cleanupProcess.send(<ICleanupDeleteActionMessage>{ actionType: CleanupProcessMessageType.AddDeleteAction, filePath });
30+
cleanupProcess.send(<IDeleteFileCleanupMessage>{ messageType: CleanupProcessMessage.AddDeleteFileAction, filePath });
3131
}
3232

3333
public async removeCleanupDeleteAction(filePath: string): Promise<void> {
3434
const cleanupProcess = await this.getCleanupProcess();
35-
cleanupProcess.send(<ICleanupDeleteActionMessage>{ actionType: CleanupProcessMessageType.RemoveDeleteAction, filePath });
35+
cleanupProcess.send(<IDeleteFileCleanupMessage>{ messageType: CleanupProcessMessage.RemoveDeleteFileAction, filePath });
3636
}
3737

3838
@exported("cleanupService")

lib/services/livesync/android-device-livesync-sockets-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class AndroidDeviceSocketsLiveSyncService extends AndroidDeviceLiveSyncSe
5959
}
6060
}
6161

62-
private async getCleanupAction(appIdentifier: string): Promise<ICleanupAction> {
62+
private async getCleanupCommand(appIdentifier: string): Promise<ISpawnCommandInfo> {
6363
return {
6464
command: await this.$staticConfig.getAdbFilePath(), args: [
6565
"-s",
@@ -86,14 +86,14 @@ export class AndroidDeviceSocketsLiveSyncService extends AndroidDeviceLiveSyncSe
8686
}
8787
}, AndroidDeviceSocketsLiveSyncService.STATUS_UPDATE_INTERVAL);
8888

89-
const cleanupAction = await this.getCleanupAction(liveSyncInfo.deviceAppData.appIdentifier);
89+
const cleanupCommand = await this.getCleanupCommand(liveSyncInfo.deviceAppData.appIdentifier);
9090
const actionOnEnd = async () => {
9191
clearInterval(syncInterval);
9292
await this.device.fileSystem.deleteFile(this.getPathToLiveSyncFileOnDevice(liveSyncInfo.deviceAppData.appIdentifier), liveSyncInfo.deviceAppData.appIdentifier);
93-
await this.$cleanupService.removeCleanupAction(cleanupAction);
93+
await this.$cleanupService.removeCleanupCommand(cleanupCommand);
9494
};
9595

96-
await this.$cleanupService.addCleanupAction(cleanupAction);
96+
await this.$cleanupService.addCleanupCommand(cleanupCommand);
9797
// We need to clear resources when the action fails
9898
// But we also need the real result of the action.
9999
await doSyncPromise.then(actionOnEnd.bind(this), actionOnEnd.bind(this));

0 commit comments

Comments
 (0)