0.1.6 • Published 6 years ago

job-runner v0.1.6

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
6 years ago

JOB RUNNER

Build Status codecov npm version

NPM NPM

For What

When you have to many jobs to run, but there is a limit of async jobs, you can try this, this runner can easily make jobs run of the max async number.

How to use

Create runner

there are two method to create a runner, use a constractor:

let Runner = jobRunner.default;
let runner = new Runner({
    source: [1,2,3],
    step: 2,
    runner: (sourceData, index) => {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve(sourceData)
            }, Math.random())
        })
    }
})

or use the create function:

let runner = jobRunner.create({
    source: [1,2,3],
    step: 2,
    runner: (sourceData, index) => {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve(sourceData)
            }, Math.random())
        })
    }
})

Just run

When you created a runner, you can just call the run of the runner to start you jobs.

console.log('jobs start to run')
runner.run().then((res) => {
    console.log('now jobs run finished')
    console.log('the result of jobs is: ', res)
})

Options

source

this is the data source of you jobs, must be an array.

step

this is the number of you parallel jobs

runner

this is you job, for how to run

group

if the group is true, you jobs will run with group one by one. Otherwise, if one of the running jobs finished, there will fill another, until there was no left.

update options

you can update options of exist runners with the setOptions function

runner.setOptions({
    step: 5
})
0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago