An open API service indexing awesome lists of open source software.

https://github.com/skyfe79/jobpipeline

A simple job pipeline package for processing tasks in sequence.
https://github.com/skyfe79/jobpipeline

Last synced: about 1 year ago
JSON representation

A simple job pipeline package for processing tasks in sequence.

Awesome Lists containing this project

README

          

# JobPipeline

A simple job pipeline package for processing tasks in sequence.

## Installation

```bash
npm install jobpipeline
```

## Usage

First, import the necessary classes:

```ts
import { Pipeline } from "jobpipeline";
import { AddJob } from "jobpipeline/dist/exampleJobs/AddJob";
import { MulJob } from "jobpipeline/dist/exampleJobs/MulJob";
```

Next, create a new Pipeline instance and add jobs to it:

```ts
const pipeline = new Pipeline();
const addJob = new AddJob();
const mulJob = new MulJob();

pipeline.addJob(addJob);
pipeline.addJob(mulJob);
```

Finally, run the pipeline:

```ts
const input = 5;
pipeline
.run(input)
.then((result) => console.log(`Result: ${result}`))
.catch((error) => console.error(`Error: ${error.message}`));
```

This will run the AddJob and MulJob in sequence, adding 1 to the input and then multiplying the result by 2.

## Creating Custom Jobs

To create a custom job, implement the Job interface:

```ts
import { Job } from "jobpipeline";

class CustomJob implements Job {
name = "CustomJob";

async run(input: InputType): Promise {
// Your custom processing logic here
}
}
```

Replace InputType and OutputType with the appropriate types for your job.

## License

This package is licensed under the MIT License.