Skip to main content

VrpcPersistor

API reference · Documentation

VrpcPersistor​

Provides a persistence layer for VRPC instances.

This class automatically saves the constructor arguments of newly created shared instances and re-creates them when the application restarts. It also listens for an 'update' event on instances to persist their state after creation (the event's payload is used as the single constructor argument upon restoration). Isolated instances belong to the connection that created them and are never persisted.

A record that cannot be restored is never deleted: it is quarantined (marked with the error, kept on disk), retried once per start so it heals by itself once the cause is fixed, and can be inspected (status), retried (retry) or removed on purpose (forget).

Kind: global class
Requires: module:@heisenware/storage


new VrpcPersistor(options)​

Creates an instance of VrpcPersistor.

Params

  • options object - Configuration options for the persistor.
    • .agentInstance VrpcAgent - The VRPC agent whose instances should be persisted.
    • [.dir] string - Optional directory for storage. Defaults to a path derived from the agent's name.
    • [.log] object - Optional logger object (e.g. console) with info, warn, and error methods.
    • [.retries] number = 5 - How often a record that fails on a fresh restore is retried before it is quarantined.
    • [.retryDelay] number = 1000 - Milliseconds between retries, multiplied by the attempt number.

vrpcPersistor.restore() ⇒ Promise.<{restored: Array.<string>, quarantined: Array.<{instance: string, className: string, error: string, attempts: number, since: string}>}>​

Restores all persisted instances from storage.

A record seen for the first time is retried with a growing delay; a record that still fails is quarantined: it stays on disk, marked with the error and the number of attempts. A quarantined record gets one attempt per restore, so it heals on the next start once its cause is fixed, and never turns a start into a retry storm.

Kind: instance method of VrpcPersistor


vrpcPersistor.status() ⇒ Promise.<{dir: string, instances: Array.<{instance: string, className: string, restoreError: (object|null)}>}>​

Lists every persisted record with its quarantine mark, if any.

Kind: instance method of VrpcPersistor


vrpcPersistor.retry(id) ⇒ Promise.<boolean>​

Attempts one more time to restore a persisted instance (quarantined or not). A success clears the quarantine mark, a failure updates it.

Kind: instance method of VrpcPersistor
Returns: Promise.<boolean> - true when the instance exists afterwards
Params

  • id string - The instance id

vrpcPersistor.forget(id) ⇒ Promise.<boolean>​

Removes a persisted record on purpose, the only way a record leaves the storage other than the deletion of a live instance.

Kind: instance method of VrpcPersistor
Returns: Promise.<boolean> - true
Params

  • id string - The instance id