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; // Create instance of process manager; // Create Tasks classes // Create Custom Process class // Register custom process inside process managerpm.register'test', CustomProcess; // Create a new instance of custom process; // subscribe on all eventsproc.on'*',console.log...args; // run custom processproc.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