Skip to content

Commit 69daf8c

Browse files
committed
chore/improve result analyz
1 parent 8d5af8b commit 69daf8c

4 files changed

Lines changed: 27 additions & 16 deletions

File tree

lib/exec.proc.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable sonarjs/cognitive-complexity */
2-
import { isFunction, isAsyncFunction, isNumber, millisecondsToMinutes } from 'sat-utils';
2+
import { isFunction, isAsyncFunction, isNumber, millisecondsToMinutes, isString, isBoolean } from 'sat-utils';
33
import { internalLogProcessResult } from './logger.execution';
44
import { execute } from './exec';
55
import { logger } from './logger';
@@ -83,19 +83,30 @@ function buildExecRunner(notRetriable, runOpts) {
8383
if (isFunction(processResultAnalyzer)) {
8484
const countInNotRetriableBeforeAnalyzation = notRetriable.length;
8585

86-
const processResultAnalyzerResultCommandOrNull = processResultAnalyzer(
87-
cmd,
88-
executionHolder.stackTrace,
89-
notRetriable,
90-
);
86+
const analyzationResult = processResultAnalyzer(cmd, executionHolder.stackTrace, notRetriable);
87+
88+
if (!isString(analyzationResult) && !isBoolean(analyzationResult)) {
89+
logger.warn('processResultAnalyzer should return boolean or string');
90+
}
91+
92+
// if analyzationResult is string - we want to re-execute command
93+
if (isString(analyzationResult)) {
94+
return resolve(analyzationResult);
95+
}
96+
97+
// if analyzationResult is true - we make assumption that process was finished successfully
98+
if (isBoolean(analyzationResult) && analyzationResult) {
99+
return resolve(null);
100+
}
91101

92102
if (
93-
!processResultAnalyzerResultCommandOrNull &&
94-
countInNotRetriableBeforeAnalyzation === notRetriable.length
103+
countInNotRetriableBeforeAnalyzation === notRetriable.length ||
104+
(isBoolean(analyzationResult) && !analyzationResult)
95105
) {
96106
notRetriable.push(cmd);
97107
}
98-
return resolve(processResultAnalyzerResultCommandOrNull);
108+
109+
return resolve(null);
99110
}
100111

101112
return resolve(cmd);

lib/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ function reRunnerBuilder(runOptions) {
1111
return intime ? intimeExecutor.bind(this, executorOptions) : circleExecutor.bind(this, executorOptions);
1212
}
1313

14-
type IBuildOpts = {
14+
export type TBuildOpts = {
1515
logLevel?: 'ERROR' | 'WARN' | 'INFO' | 'VERBOSE' | 'MUTE';
1616
maxThreads?: number;
1717
attemptsCount?: number;
1818
longestProcessTime?: number;
1919
successExitCode?: number;
2020
pollTime?: number;
21-
processResultAnalyzer?: (originalCommand: string, stack: string, notRetriable: any[]) => string | null | void;
21+
processResultAnalyzer?: (originalCommand: string, stack: string, notRetriable: any[]) => string | boolean;
2222
everyCycleCallback?: () => void;
2323
watcher?: () => void;
2424
currentExecutionVariable?: string;
@@ -32,7 +32,7 @@ type IBuildOpts = {
3232
onErrorProcess?: (execProc, error) => void;
3333
};
3434

35-
type IRunner = {
35+
export type TRunner = {
3636
(commands: string[]): Promise<{ notRetriable: string[]; retriable: string[] }>;
3737
};
3838

@@ -43,7 +43,7 @@ const getReruner = ({
4343
pollTime = 1000,
4444
successExitCode = 0,
4545
...rest
46-
}: IBuildOpts = {}): IRunner => {
46+
}: TBuildOpts = {}): TRunner => {
4747
const reformattedArgs = {
4848
longestProcessTime,
4949
maxThreads,
@@ -56,6 +56,6 @@ const getReruner = ({
5656
return reRunnerBuilder(reformattedArgs);
5757
};
5858

59-
export { getReruner, IBuildOpts, IRunner };
59+
export { getReruner };
6060

6161
export { getFilesList } from './helpers';

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.9",
3+
"version": "0.3.0",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/potapovDim/protractor-rerun.git"

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ arguments | description
2525
**`buildOpts.logLevel`** | Type: `string`, one of 'ERROR', 'WARN', 'INFO', 'VERBOSE', 'MUTE' <br> ERROR - only errors, WARN - errors and warnings, INFO - errors, warnings and information, VERBOSE - full logging, MUTE - mute execution output <br> **Default is 'ERROR'**
2626
**`buildOpts.currentExecutionVariable`** | **Optional** Type: `string`, will be execution variable with execution index for every cycle will be ++<br>
2727
**`buildOpts.everyCycleCallback`** | **Optional** Type: `function`, <br> Optional. everyCycleCallback will be executed after cycle, before next execution cycle.<br> **Default is false**
28-
**`buildOpts.processResultAnalyzer`** | **Optional** Type: `function`, <br> Optional. processResultAnalyzer is a function where arguments are original command, execution stack trace and notRetriable array processResultAnalyzer should return a new command what will be executed in next cycle or **null** - if satisfactory result <br>
28+
**`buildOpts.processResultAnalyzer`** | **Optional** Type: `function`, <br> Optional. processResultAnalyzer is a function where arguments are original command, execution stack trace and notRetriable array processResultAnalyzer should return a new command what will be executed in next cycle or **boolean** - if satisfactory result <br>
2929
**`buildOpts.longestProcessTime`** | **Optional** Type: `number`, <br> In case if command execution time is longer than longest Process Time - executor will kill it automatically and will try to execute this command again. <br> **Default time is 45 seconds**
3030

3131
## Usage

0 commit comments

Comments
 (0)