You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

process-rerun

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

process-rerun

The purpose of this library is - build simple and flexible interface for parallel command execution with rerun (on fail) possibility

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
545
-54.36%
Maintainers
1
Weekly downloads
 
Created
Source

process-rerun

The purpose of this library is - build simple and flexible interface for parallel command execution with rerun (on fail) possibility

npm downloads

Documents
Usage
Changelog

Documents

buildRunner(buildOpts): returns rerunner: function(string[]): {retriable: string[]; notRetriable: string[]}

argumentsdescription
buildOptsType: object
Options for executor
buildOpts.maxThreadsOptional Type: number,
How many threads can be executed in same time
Default threads count is 5
buildOpts.intimeOptional Type: boolean,
if intime is true intime execution approach will be enabled
Default is false
buildOpts.shuffleOptional Type: boolean,
Shuffle commands during execution
Default threads count is 5
buildOpts.attemptsCountOptional Type: number,
How many times can we try to execute command for success result in next cycle will be executed only faild command, success commands will not be reexecuted
Default attempts count is 2
buildOpts.pollTimeOptional Type: number,
Period for recheck about free thread
Default is 1 second
buildOpts.successExitCodeOptional Type: number,
Exit code what will be used for succes process check
Default is 0
buildOpts.logLevelType: string, one of 'ERROR', 'WARN', 'INFO', 'VERBOSE', 'MUTE'
ERROR - only errors, WARN - errors and warnings, INFO - errors, warnings and information, VERBOSE - full logging, MUTE - mute execution output
Default is 'ERROR'
buildOpts.currentExecutionVariableOptional Type: string, will be execution variable with execution index for every cycle will be ++
buildOpts.everyCycleCallbackOptional Type: function,
Optional. everyCycleCallback will be executed after cycle, before next execution cycle.
Default is false
buildOpts.processResultAnalyzerOptional Type: function,
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
buildOpts.longestProcessTimeOptional Type: number,
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.
Default time is 45 seconds

Usage

const { buildRunner } = require('process-rerun');

async function execCommands() {
  const runner = buildRunner({
    maxThreads: 10, // ten threads
    attemptsCount: 2, // will try to pass all commands two times, one main and one times rerun
    longestProcessTime: 60 * 1000, // if command process execution time is longre than 1 minute will kill it and try to pass in next cycle
    pollTime: 1000, // will check free thread every second
    everyCycleCallback: () => console.log('Cycle done'),
    processResultAnalyzer: (cmd, stackTrace, notRetriableArr) => {
      if (stackTrace.includes('Should be re executed')) {
        return cmd;
      }
      notRetriableArr.push(cmd);
    }, //true - command will be reexecuted
  });
  const result = await runner([
    `node -e 'console.log("Success first")'`,
    `node -e 'console.log("Success second")'`,
    `node -e 'console.log("Failed first"); process.exit(1)'`,
    `node -e 'console.log("Success third")'`,
    `node -e 'console.log("Failed second"); process.exit(1)'`,
  ]);

  console.log(result);
  /*
  {
    retriable: [
      `node -e 'console.log("Failed first"); process.exit(1)' --opt1=opt1value --opt1=opt1value`,
      `node -e 'console.log("Failed second"); process.exit(1)' --opt1=opt1value --opt1=opt1value`
    ],
    notRetriable: []
  }
  */
}

intime approach vs circle approach

circle approach

five processes execution, two execution attempts, five parallel execution

first execution attempt (three failed)second execution attempt (one failed)third execution attempt (o failed)
1 p1 --------------------------> successp2 ---> successp4 -----------> success
2 p2 ---> failp4 -----------> fail
3 p3 -------> failp3 -------> success
4 p4 -----------> fail
5 p5 -----> success

Full execution time:
p1 (first attempt) --------------------------> + p4 (second attempt) -----------> + (third attempt) p4 ----------->

intime approach (with same fail scheme)

every process has attemp count timer

f - fail
s - success
1 p1 -------------------------->s
2 p2 --->f--->s
3 p3 ------->f------->s
4 p4 ----------->f
5 p5 ----->s(p4)----------->f----------->s

Full execution time:

5 p5 ----->s(p4)----------->f----------->s

Failed process will check that free parallel exists and start execution when free parallel will be found.

Changelog

Version 0.1.11

Keywords

flaky

FAQs

Package last updated on 22 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts