Skip to content

Commit 5cfeafb

Browse files
committed
change error and exit/close infor handling
1 parent 6c11cbb commit 5cfeafb

5 files changed

Lines changed: 30 additions & 20 deletions

File tree

lib/exec.proc.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function buildExecRunner(notRetriable, runOpts) {
1414
pollTime,
1515
successExitCode = 0,
1616
logProcessResult = internalLogProcessResult,
17+
onExitCloseProcess,
18+
onErrorProcess,
1719
} = runOpts;
1820

1921
if (!isNumber(successExitCode)) {
@@ -52,17 +54,18 @@ function buildExecRunner(notRetriable, runOpts) {
5254

5355
const watcher = setInterval(() => killTooLongExecution(execProc), pollTime);
5456

55-
execProc.on('exit', (code, signal) => {
56-
logger.info(`EXIT PROCESS: PID="${execProc.pid}", code="${code}" and signal="${signal}"`);
57-
});
57+
if (onExitCloseProcess) {
58+
execProc.on('exit', (code, signal) => onExitCloseProcess(execProc, code, signal));
59+
}
5860

59-
execProc.on('error', e => {
60-
logger.info(`ERROR PROCESS: PID="${execProc.pid}"`);
61-
logger.error(e);
62-
});
61+
if (onErrorProcess) {
62+
execProc.on('error', error => onErrorProcess(execProc, error));
63+
}
6364

6465
execProc.on('close', async (code, signal) => {
65-
logger.info(`CLOSE PROCESS: PID="${execProc.pid}", code="${code}" and signal="${signal}"`);
66+
if (onExitCloseProcess) {
67+
onExitCloseProcess(execProc, code, signal);
68+
}
6669

6770
// clear watcher interval
6871
clearInterval(watcher);

lib/executor.circle.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ async function circleExecutor(runOptions, commandsArray): Promise<{ retriable: s
3232
logEndCycle = internalLogEndCycle,
3333
logIteractionCycle = internalLogIteractionCycle,
3434
logMiddleResultsCycle = internalLogMiddleResultsCycle,
35+
onExitCloseProcess,
36+
onErrorProcess,
3537
} = runOptions;
3638

3739
/**
@@ -50,6 +52,8 @@ async function circleExecutor(runOptions, commandsArray): Promise<{ retriable: s
5052
pollTime,
5153
successExitCode,
5254
logProcessResult,
55+
onExitCloseProcess,
56+
onErrorProcess,
5357
});
5458

5559
async function runCommand(commands, retriable, runIndex) {

lib/helpers.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3-
import {ProcessRerunError} from './error';
4-
5-
const getFilesList = function(dir: string, fileList: string[] = [], directoryToSkip: string[] = [], ignoreSubDirs?: boolean): string[] {
3+
import { ProcessRerunError } from './error';
4+
5+
const getFilesList = function (
6+
dir: string,
7+
fileList: string[] = [],
8+
directoryToSkip: string[] = [],
9+
ignoreSubDirs?: boolean,
10+
): string[] {
611
if (!fs.existsSync(dir)) {
712
throw new ProcessRerunError('FileSystem', `${dir} does not exists`);
813
}
914

1015
const files = fs.readdirSync(dir);
1116

12-
files.forEach(function(file) {
17+
files.forEach(function (file) {
1318
const isDirr = fs.statSync(path.join(dir, file)).isDirectory();
1419

1520
const shouldBeExcluded =
@@ -32,15 +37,11 @@ const getFilesList = function(dir: string, fileList: string[] = [], directoryToS
3237
};
3338

3439
function getPollTime(timeVal: any): number {
35-
return typeof timeVal === 'number' && !isNaN(timeVal) && isFinite(timeVal) ? timeVal : 1000;
40+
return typeof timeVal === 'number' && !Number.isNaN(timeVal) && Number.isFinite(timeVal) ? timeVal : 1000;
3641
}
3742

3843
function sleep(time: number): Promise<void> {
39-
return new Promise((res) => setTimeout(res, time));
44+
return new Promise(res => setTimeout(res, time));
4045
}
4146

42-
export {
43-
getPollTime,
44-
sleep,
45-
getFilesList,
46-
};
47+
export { getPollTime, sleep, getFilesList };

lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type IBuildOpts = {
2828
logIteractionCycle?: (cycleNumber: number, commands: string[]) => void;
2929
logMiddleResultsCycle?: (initialCount: number, commands: string[]) => void;
3030
logProcessResult?: (cmd: string, startTime: number, execProc, error, stdout, stderr) => void;
31+
onExitCloseProcess?: (execProc, code: null, signal: string | number) => void;
32+
onErrorProcess?: (execProc, error) => void;
3133
};
3234

3335
type IRunner = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "process-rerun",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/potapovDim/protractor-rerun.git"

0 commit comments

Comments
 (0)