ontime-pm
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Ontime Process manager

The library is used to manage and control some processes which you are able to run in the browser or NodeJS. There is sometimes need to split a complicated process into small pieces of code. It means that you can create simple tasks and combine them into the one process.

Process manager - allows you to controll your processes.

Process - allows you to controll tasks.

Task - simple iteration.


Install

yarn add ontime-pm
 
// or
 
npm install ontime-pm

Example

// index.ts
import { ProcessManager, Process, Task } from 'ontime-pm';
 
// Create instance of process manager
const processManager: ProcessManager = new ProcessManager('user');
 
// Create Tasks classes
class Task1 extends Task {
  
  async run() {
    console.log('Task 1. Do something...');
  }
 
  async pause() {}
  async resume() {}
  async cancel() {}
}
 
class Task2 extends Task {
  
  async run() {
    console.log('Task 2. Do something...');
  }
 
  async pause() {}
  async resume() {}
  async cancel() {}
}
 
class Task3 extends Task {
  
  async run() {
    console.log('Task 3. Do something...');
  }
 
  async pause() {}
  async resume() {}
  async cancel() {}
}
 
// Create Custom Process class
class CustomProcess extends Process<{}, []> {
  public get name(): string { return 'test'; }
  public get tasks(): any[] { return [Task1, Task2, Task3]; }
}
 
// Register custom process inside process manager
pm.register('test', CustomProcess);
 
// Create a new instance of custom process
const proc: CustomProcess = await pm.create('test');
 
// subscribe on all events
proc.on('*', (...args: any[]) => console.log(...args));
 
// run custom process
proc.run();

Process manager

constructor(userId: string = '')

- userId - Optional. User ID.

register<P>(processName: string, procClass: P): void

The method registers a class process in the system - processName - process name - procClass - process class

create<P, V>(processName: string, options: V, restoreId?: string): Promise<P>

The method creates new process instance. The method returns new instance.
- processName - process name
- options - process variables
- restoreId. Optional. Using for restore process context.

status(processId: string): Promise<TStatus>

The method returns a status of an instance of a process
- processId - process ID

get(processId: string): Promise<Process>

The method returns an instance of Process by a process ID
- processId - process ID

list(): Promise<Process[]>

The method returns a list of active processes

Process<V, T extends Task[] | Function[]>

  • V generic of variables

id: string

Process ID

name: string

Process name. Getter property.

tasks: T[]

Process tasks. Getter property.

constructor(userId: string = '', vars: V | Object = {}, restoreId?: string)

- userId - Optional. User ID. - vars - Optional. Process variables. - restoreId - Optional. Using for restore process context.

run(): Promise<void>

The method runs the process to execute

cancel(): Promise<void>

The method cancels the process

pause(): Promise<void>

The method pauses the process

resume(): Promise<void>

The method resumes the process

status(): Promise<TStatus>

The method returns a status of the process

getVars(): Promise<V>

The method returns process variables

Task

destroy(): void

Destructor

cancel(): Promise<void>

The method cancels the task

pause(): Promise<void>

The method pauses the task

resume(): Promise<void>

The method resumes the task

Others API depends on the implementation

Readme

Keywords

Package Sidebar

Install

npm i ontime-pm

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

105 kB

Total Files

20

Last publish

Collaborators

  • ontimelengo