Code Monkey home page Code Monkey logo

batch-process's Introduction

batch-process - a Node.js module for controlling batch processes

This module executes external processes, capturing output and reporting on status.

Used by the seneca-run plugin to execute external processes.

Build Status

NPM NPM

If you're using this module, feel free to contact me on twitter if you have any questions! :) @rjrodger

Current Version: 0.1.0

Tested on: Node 0.10.31

Install

To install:

npm install batch-process

Quick Example

var batch_process = require('batch-process')

// define a batch process
// with common options
var batch = batch_process({
  command:'ls',
  args:['-lisa']
})

// create a new process with
// its own overridden options
var proc = batch.make_process({
  cwd:__dirname
})

// listen for the 'report' event
// errors are also reported this way
proc.on('report',function(rep){
  console.log(rep)

  if( rep.final ) {
    console.log('FINISHED')
  }
})

// actually execute the external process
proc.run()

Process Execution

Processes are run with child_process.spawn. The working directory is the current process directory, unless set explicitly via options (see below). Each process is given a unique indentifier in the format: name-timestamp-random.

The processes are not executed in a shell, so you must supply explicit arguments and full paths. You can provide environment variables with the env option.

The standard output and error are recorded and saved, both in-memory and to disk. The in-memory size is limited to a maximum (see options below). The disk recording is to /tmp by default. A new sub-folder is created each time, with files stdout and stderr containing their respective output.

Options

The options can be set at two levels. When defining a batch process with

var batch = batch_process({
  command:'ls',
  args:['-lisa']
})

And when running a process instance, with

var proc = batch.make_process({
  cwd:__dirname
})

The same options can be used at each level. Use the process options to override the common batch options to specialize the process execution.

The options are:

  • command: Process to execute. Use an absolute path if in doubt.
  • name: Name of batch process. For your own use. Default: command
  • args: Arguments for process. Default: []
  • cwd: Current working directory for process. Default: current.
  • env: Environment variables for process. Default: null
  • report_interval: Time between periodic emits of record event. If 0, then disabled.
  • timeout: Max time allowed for process to exit. For no limit, use 0. Default: 333333.
  • capture_size: Max in-memory size of output capture. Must be > 0. Default: 22222.
  • record_folder: Folder for output capture files. Default: '/tmp/batch_process'.
  • record: Record output flag. Default: true.
  • kill_signal: Signal sent to timedout process. Default: 'SIGTERM'.
  • uid: User id for process.
  • gid: Group id for process.

Testing

Unit tests use mocha, and can be run with:

npm test

Releases

  • 0.1.0: initial release

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.