batchjs
v1.0.1
Published
Batch processing framework for NodeJS
Downloads
12
Maintainers
Readme
BatchJS
Dependencies free batch processing framework for NodeJS based on streams.
Download
NPM
npm install batchjs
Yarn
yarn add batchjs
Usage
import { Job, Step } from "batchjs";
// Implement a step
class StepImplementation extends Step {
// Set a name to the step
constructor(name: string = "MockPassingStep") {
super(name);
}
// Implement the reader to load step data source
protected _reader() {
return new Readable({
objectMode: true,
read() {
this.push("data");
this.push(null);
},
});
}
// Implement the processors to transform data sequently using our streams or your own streams
protected _processors() {
const opts: TransformOptions = {
objectMode: true,
transform(
chunk: unknown,
encoding: BufferEncoding,
callback: TransformCallback
) {
this.push(chunk);
callback();
},
};
return [new Transform(opts), new Transform(opts)];
}
// Implement the write to stock final step data
protected _writer() {
return new Writable({
objectMode: true,
write(
chunk: unknown,
encoding: BufferEncoding,
callback: TransformCallback
) {
callback();
},
});
}
}
// Implement a Job
class JobImplementation extends Job {
// Implement to set the steps to be sequently executed.
protected _steps() {
return [new StepImplementation(), new StepImplementation()];
}
}
// Instance the Job
const job = new JobImplementation("My job");
// Set events listener
job.on("stepStart", (step: step) => {
console.log(`Starting step ${step.name}`);
});
// Launch the job
job
.run()
.then(() => {
console.log("Job completed successfully");
})
.catch((error) => {
console.log("Job completed with errors");
});
Documentation
Collaborators welcom!
- ¿Do you like the project? Give us a :star: in GitHub.
- :sos: ¿Do you need some help? Open a discussion in GitHub help wanted
- :bug: ¿Do you find a bug? Open a issue in GitHub bug report
- :bulb: ¿Do you have a great idea? Open a issue in GitHub feature request
- :computer: ¿Do you know how to fix a bug? Open a pull request in GitHub pull repuest.
- ¿Do you know a security issue? Take a read to our security strategy.
Suscribe our code of conduct and follow the Contribution Guidelines.