Skip to content

Commit 39ff1bb

Browse files
committed
[PROCESS RERUN]: remove utils
1 parent 7991f99 commit 39ff1bb

File tree

10 files changed

+139
-192
lines changed

10 files changed

+139
-192
lines changed

lib/executor.circle.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,18 @@ async function circleExecutor(runOptions, commandsArray): Promise<{ retriable: s
9191

9292
const asserter = setInterval(() => runCommand(commands, retriable, executionCount), pollTime);
9393

94-
const logProcessesProgressLogger =
95-
logProcessesProgress &&
96-
setInterval(() => logMiddleResultsCycle(initialCommandsCount, commands, inProgressCommands), 5000);
97-
98-
const watcherRunner = watcher && setInterval(() => watcher(Array.from(notRetriable), Array.from(retriable)), 5000);
94+
const watcherRunner =
95+
watcher &&
96+
setInterval(
97+
() =>
98+
watcher({
99+
notRetriable: Array.from(notRetriable),
100+
retriable: Array.from(retriable),
101+
inProgressCommands: Array.from(inProgressCommands),
102+
initialCommandsCount,
103+
}),
104+
5000,
105+
);
99106

100107
do {
101108
if (commands.length) {
@@ -114,10 +121,6 @@ async function circleExecutor(runOptions, commandsArray): Promise<{ retriable: s
114121
}
115122
}
116123

117-
if (logProcessesProgressLogger) {
118-
clearInterval(logProcessesProgressLogger);
119-
}
120-
121124
if (watcherRunner) {
122125
clearInterval(watcherRunner);
123126
}

lib/executor.intime.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { shuffleArrMutable, isString, isFunction, isAsyncFunction } from 'sat-utils';
1+
import { isString, isFunction, isAsyncFunction } from 'sat-utils';
22
import { buildCommandExecutor } from './command.executor.builder';
33
import { sleep } from './helpers';
44
import { logger } from './logger';
5-
import {
6-
internalLogStartCycle,
7-
internalLogEndCycle,
8-
internalLogMiddleResultsCycle,
9-
internalLogIntimeCommand,
10-
} from './logger.execution';
11-
12-
async function intimeExecutor(runOptions, commandsArray): Promise<{ retriable: string[]; notRetriable: string[] }> {
5+
import { internalLogStartCycle, internalLogEndCycle, internalLogIntimeCommand } from './logger.execution';
6+
7+
import type { TBuildOpts } from './lib.types';
8+
9+
async function intimeExecutor(
10+
runOptions: TBuildOpts,
11+
commandsArray,
12+
): Promise<{ retriable: string[]; notRetriable: string[] }> {
1313
const notRetriable = [];
1414
const retriable = [];
1515

@@ -23,12 +23,9 @@ async function intimeExecutor(runOptions, commandsArray): Promise<{ retriable: s
2323
successExitCode,
2424
currentExecutionVariable,
2525
maxThreads,
26-
shuffle,
2726
watcher,
28-
logProcessesProgress,
2927
logStartCycle = internalLogStartCycle,
3028
logEndCycle = internalLogEndCycle,
31-
logMiddleResultsCycle = internalLogMiddleResultsCycle,
3229
logIntimeCommand = internalLogIntimeCommand,
3330
execOpts,
3431
} = runOptions;
@@ -53,9 +50,7 @@ async function intimeExecutor(runOptions, commandsArray): Promise<{ retriable: s
5350
async function runCommand(commands) {
5451
if (maxThreads > currentSessionCount && commands.length) {
5552
currentSessionCount += 1;
56-
if (shuffle) {
57-
shuffleArrMutable(commands);
58-
}
53+
5954
let result;
6055
const commadData = commands.splice(0, 1)[0] as { cmd; attemptsCount: number };
6156

@@ -90,11 +85,18 @@ async function intimeExecutor(runOptions, commandsArray): Promise<{ retriable: s
9085
const initialCommandsCount = commands.length;
9186
const asserter = setInterval(() => runCommand(commands), pollTime);
9287

93-
const logProcessesProgressLoggerRunner =
94-
logProcessesProgress &&
95-
setInterval(() => logMiddleResultsCycle(initialCommandsCount, commands, inProgressCommands), 5000);
96-
97-
const watcherRunner = watcher && setInterval(() => watcher(Array.from(notRetriable), Array.from(retriable)), 5000);
88+
const watcherRunner =
89+
watcher &&
90+
setInterval(
91+
() =>
92+
watcher({
93+
notRetriable: Array.from(notRetriable),
94+
retriable: Array.from(retriable),
95+
inProgressCommands: Array.from(inProgressCommands),
96+
initialCommandsCount,
97+
}),
98+
5000,
99+
);
98100

99101
do {
100102
if (commands.length) {
@@ -109,9 +111,7 @@ async function intimeExecutor(runOptions, commandsArray): Promise<{ retriable: s
109111
);
110112

111113
clearInterval(asserter);
112-
if (logProcessesProgressLoggerRunner) {
113-
clearInterval(logProcessesProgressLoggerRunner);
114-
}
114+
115115
if (watcherRunner) {
116116
clearInterval(watcherRunner);
117117
}

lib/helpers.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,3 @@
1-
import * as fs from 'fs';
2-
import * as path from 'path';
3-
import { ProcessRerunError } from './error';
4-
5-
const getFilesList = function (
6-
dir: string,
7-
fileList: string[] = [],
8-
directoryToSkip: string[] = [],
9-
ignoreSubDirs?: boolean,
10-
): string[] {
11-
if (!fs.existsSync(dir)) {
12-
throw new ProcessRerunError('FileSystem', `${dir} does not exists`);
13-
}
14-
15-
const files = fs.readdirSync(dir);
16-
17-
files.forEach(function (file) {
18-
const isDirr = fs.statSync(path.join(dir, file)).isDirectory();
19-
20-
const shouldBeExcluded =
21-
(Array.isArray(directoryToSkip) && directoryToSkip.includes(file)) ||
22-
(typeof directoryToSkip === 'string' && file.includes(directoryToSkip)) ||
23-
(directoryToSkip instanceof RegExp && file.match(directoryToSkip));
24-
25-
if (shouldBeExcluded) {
26-
return;
27-
}
28-
29-
if (isDirr && !ignoreSubDirs) {
30-
fileList = getFilesList(path.join(dir, file), fileList, directoryToSkip, ignoreSubDirs);
31-
} else if (!isDirr) {
32-
fileList.push(path.join(dir, file));
33-
}
34-
});
35-
36-
return fileList;
37-
};
38-
391
function getPollTime(timeVal: any): number {
402
return typeof timeVal === 'number' && !Number.isNaN(timeVal) && Number.isFinite(timeVal) ? timeVal : 1000;
413
}
@@ -44,4 +6,4 @@ function sleep(time: number): Promise<void> {
446
return new Promise(res => setTimeout(res, time));
457
}
468

47-
export { getPollTime, sleep, getFilesList };
9+
export { getPollTime, sleep };

lib/index.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { logger } from 'sat-utils';
22
import { getPollTime } from './helpers';
33
import { circleExecutor } from './executor.circle';
44
import { intimeExecutor } from './executor.intime';
5-
import type { ExecOptions } from 'child_process';
5+
6+
import type { TBuildOpts } from './lib.types';
67

78
function reRunnerBuilder(runOptions) {
89
const { logLevel = 'ERROR', intime = false, ...executorOptions } = runOptions;
@@ -12,28 +13,6 @@ function reRunnerBuilder(runOptions) {
1213
return intime ? intimeExecutor.bind(this, executorOptions) : circleExecutor.bind(this, executorOptions);
1314
}
1415

15-
export type TBuildOpts = {
16-
logLevel?: 'ERROR' | 'WARN' | 'INFO' | 'VERBOSE' | 'MUTE';
17-
maxThreads?: number;
18-
attemptsCount?: number;
19-
longestProcessTime?: number;
20-
successExitCode?: number;
21-
pollTime?: number;
22-
execOpts?: ExecOptions;
23-
processResultAnalyzer?: (originalCommand: string, stack: string, notRetriable: any[]) => string | boolean;
24-
everyCycleCallback?: () => void;
25-
watcher?: (notRetriable?: string[], retriable?: string[]) => void;
26-
currentExecutionVariable?: string;
27-
logProcessesProgress?: boolean;
28-
logStartCycle?: (maxThreads: number | string, attemptsCount: number | string, inTimeCommands: string[]) => void;
29-
logEndCycle?: (retriable: string[], notRetriable: string[], startTime: number) => void;
30-
logIteractionCycle?: (cycleNumber: number, commands: string[]) => void;
31-
logMiddleResultsCycle?: (initialCount: number, commands: string[], commandsInProgressArr: string[]) => void;
32-
logProcessResult?: (cmd: string, startTime: number, execProc, error, stdout, stderr) => void;
33-
onExitCloseProcess?: (execProc, code: null, signal: string | number) => void;
34-
onErrorProcess?: (execProc, error) => void;
35-
};
36-
3716
export type TRunner = {
3817
(commands: string[] | Array<(index: number) => any>): Promise<{ notRetriable: string[]; retriable: string[] }>;
3918
};
@@ -58,6 +37,5 @@ const getReruner = ({
5837
return reRunnerBuilder(reformattedArgs);
5938
};
6039

40+
export type { TBuildOpts } from './lib.types';
6141
export { getReruner };
62-
63-
export { getFilesList } from './helpers';

lib/lib.types.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { ExecOptions } from 'child_process';
2+
3+
export type TBuildOpts = {
4+
logLevel?: 'ERROR' | 'WARN' | 'INFO' | 'VERBOSE' | 'MUTE';
5+
maxThreads?: number;
6+
attemptsCount?: number;
7+
longestProcessTime?: number;
8+
successExitCode?: number;
9+
pollTime?: number;
10+
execOpts?: ExecOptions;
11+
processResultAnalyzer?: (originalCommand: string, stack: string, notRetriable: any[]) => string | boolean;
12+
everyCycleCallback?: () => void;
13+
watcher?: (data: {
14+
notRetriable?: string[];
15+
retriable?: string[];
16+
inProgressCommands?: string[];
17+
initialCommandsCount?: number;
18+
}) => void;
19+
currentExecutionVariable?: string;
20+
logStartCycle?: (maxThreads: number | string, attemptsCount: number | string, inTimeCommands: string[]) => void;
21+
logEndCycle?: (retriable: string[], notRetriable: string[], startTime: number) => void;
22+
logIteractionCycle?: (cycleNumber: number, commands: string[]) => void;
23+
logProcessResult?: (cmd: string, startTime: number, execProc, error, stdout, stderr) => void;
24+
onExitCloseProcess?: (execProc, code: null, signal: string | number) => void;
25+
onErrorProcess?: (execProc, error) => void;
26+
logIntimeCommand?: (commadData: { cmd: string; attemptsCount: number }) => void;
27+
};

package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
{
22
"name": "process-rerun",
3-
"version": "0.5.0",
3+
"version": "1.0.0",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/potapovDim/protractor-rerun.git"
77
},
8-
"main": "./built/index.js",
8+
"main": "./built/cjs/index.js",
9+
"exports": {
10+
".": {
11+
"require": "./built/cjs/index.js",
12+
"import": "./built/esm/index.js"
13+
}
14+
},
915
"scripts": {
1016
"tscw": "tsc -w",
1117
"validate": "npm ls",
1218
"test": "mocha $(find specs -name '*.spec.*') --timeout 500000 --require ts-node/register",
13-
"tsc": "rm -rf ./built && tsc",
19+
"tsc:cjs": "tsc -p tsconfig.json",
20+
"tsc:esm": "tsc -p tsconfig.esm.json",
21+
"tsc": "rm -rf ./built && npm run tsc:cjs && npm run tsc:esm",
1422
"lint": "eslint --ext .ts ./ --fix"
1523
},
1624
"author": {
@@ -32,7 +40,7 @@
3240
],
3341
"devDependencies": {
3442
"@types/mocha": "^9.1.1",
35-
"@types/node": "^14.17.1",
43+
"@types/node": "^22.14.1",
3644
"@typescript-eslint/eslint-plugin": "^5.21.0",
3745
"@typescript-eslint/parser": "^5.21.0",
3846
"assertior": "0.0.11",
@@ -45,14 +53,14 @@
4553
"eslint-plugin-sonarjs": "^0.13.0",
4654
"eslint-plugin-unicorn": "^42.0.0",
4755
"mocha": "^10.0.0",
48-
"ts-node": "^5.0.1",
56+
"ts-node": "^10.9.1",
4957
"tslint": "^5.9.1",
50-
"typescript": "^4.3.2"
58+
"typescript": "^5.0.4"
5159
},
5260
"engines": {
53-
"node": ">=10.22.0"
61+
"node": ">=19.22.0"
5462
},
5563
"dependencies": {
5664
"sat-utils": "0.0.49"
5765
}
58-
}
66+
}

0 commit comments

Comments
 (0)