child-processor.d.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Receiver, SandboxedJob } from '../interfaces';
  2. import { JobJsonSandbox } from '../types';
  3. declare enum ChildStatus {
  4. Idle = 0,
  5. Started = 1,
  6. Terminating = 2,
  7. Errored = 3
  8. }
  9. /**
  10. * ChildProcessor
  11. *
  12. * This class acts as the interface between a child process and it parent process
  13. * so that jobs can be processed in different processes.
  14. *
  15. */
  16. export declare class ChildProcessor {
  17. private send;
  18. private receiver;
  19. status?: ChildStatus;
  20. processor: any;
  21. currentJobPromise: Promise<unknown> | undefined;
  22. private abortController?;
  23. constructor(send: (msg: any) => Promise<void>, receiver: Receiver);
  24. init(processorFile: string): Promise<void>;
  25. start(jobJson: JobJsonSandbox, token?: string): Promise<void>;
  26. /**
  27. * Cancels the currently running job by aborting its signal.
  28. * @param reason - Optional reason for the cancellation
  29. */
  30. cancel(reason?: string): void;
  31. stop(): Promise<void>;
  32. waitForCurrentJobAndExit(): Promise<void>;
  33. /**
  34. * Enhance the given job argument with some functions
  35. * that can be called from the sandboxed job processor.
  36. *
  37. * Note, the `job` argument is a JSON deserialized message
  38. * from the main node process to this forked child process,
  39. * the functions on the original job object are not in tact.
  40. * The wrapped job adds back some of those original functions.
  41. */
  42. protected wrapJob(job: JobJsonSandbox, send: (msg: any) => Promise<void>): SandboxedJob;
  43. }
  44. export {};