0.2.6 • Published 8 months ago

warp-core-worker v0.2.6

Weekly downloads
-
License
MIT
Repository
-
Last release
8 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.6

8 months ago

0.2.5

11 months ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.2

1 year ago

0.1.0

1 year ago

0.1.1

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago