0.2.3 • Published 2 months ago

warp-core-worker v0.2.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

warp-core-worker

Task class framework and Task Orchestrator

Features:

  • Abstract Task class (Task)

    • Currently three trigger types: instant, scheduled, and interval.
    • Methods to handle preStart and post task execution.
      • preStart can be also is used to check if we need to execute the task. (in case reloading, re-triggering or no new data to process).
    • Rerun method to decide conditions to rerun the task.
    • Internal state data like, errors, run and error counts, start and stop Dates, etc.
  • Task Orchestrator (Worker)

    • Task registration and initialization.
    • waitTask method to wait Promise for task completion (only for instant tasks).
    • callback to get task changes (i.e. save to db, send to client as events, etc.)
    • import method to import tasks on restarts. (i.e. from db, etc.)
      • restarts tasks which was running before restart.
    • Task abort.
    • Control Task re-runs/retry.
    • Customizable shared context for all task instances (i.e. have task owner, etc.)

Minimal Example

class Demo extends AbstractSimpleTask<'demo', {test: string}, string, unknown> {
	public readonly type = 'demo';
	public trigger: TaskTrigger = {type: 'instant'};
	protected buildDescription(): Promise<string> {
		return Promise.resolve(`${this.type} ${this.props.test}`);
	}

	public runTask(): Promise<string> {
		return Promise.resolve('demo');
	}
}

const worker = new Worker({
	taskUniqueIdBuilder: () => uuid(),
	// logger: console,
});

const task = await worker.initializeTask(Demo, {test: 'test'}, {}); // arg 1 is task class, arg 2 is current tasks props, arg 3 is common context.
await worker.startTask(task); // optional, waitTask will call startTask if not started yet.
const data = await worker.waitTask(task);

Detailed API Documentation.

TODO

  • remove promises other than instant task trigger
  • remove custom callback setup and use Event Emitter instead
0.2.3

2 months ago

0.2.1

2 months ago

0.2.0

2 months ago

0.2.2

2 months ago

0.1.0

2 months ago

0.1.1

2 months ago

0.0.15

2 months ago

0.0.14

3 months ago

0.0.13

3 months ago

0.0.12

3 months ago

0.0.11

3 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago