import Replicator from '@cansat-icarus/capture-lib/src/icarus/backend/replicator.js'
Replicator
Extends:
Handles replication between a local and remote PouchDB database. Keeps track of state, uses an ExponentialBackoff to prevent connection saturation, serving as a wrapper over PouchDB replication.
The source database is set once in the constructor and remains unchanged and unchangeable during operation.
Constructor Summary
Public Constructor | ||
public |
constructor(logger: Logger, sourceDB: PouchDB) |
Member Summary
Private Members | ||
private |
ExponentialBackoff instance. |
|
private |
_log: Bunyan Logger instance. |
|
private |
_replication: PouchDBReplicationID PouchDB replication instance/ID. |
|
private |
_sourceDB: PouchDB Source database. |
|
private |
Replicator status. |
|
private |
_targetDB: PouchDB Target database. |
Method Summary
Public Methods | ||
public |
Stops current replication and attempts last-minute replication. |
|
public |
Starts replication to a remote database. |
|
public |
stop() Stops the replication process. |
Private Methods | ||
private |
|
|
private |
_createReplicator(opts: Object): PouchDBReplicationID Creates a new PouchDB replicator. |
|
private |
_ensureReplication(retry: Number) Restarts the replication process when unintentionally stopped. |
|
private |
_updateState(state: String, moreLogData: Object) Updates the Replicator's Replicator#_state. |
Public Constructors
public constructor(logger: Logger, sourceDB: PouchDB) source
Params:
Name | Type | Attribute | Description |
logger | Logger | Bunyan logger instance. |
|
sourceDB | PouchDB | Database to be replicated. |
Private Members
private _backoff: ExponentialBackoff source
ExponentialBackoff instance. Keeps track of the replication backoff.
Public Methods
public async cleanup(): Promise source
Stops current replication and attempts last-minute replication. Last-minute replication is done in "one-shot" mode: replicates whatever data it has and immediately stops without listening for changes in the local database.
Emit:
* |
state('cleanup') |
public replicate(dbName: String, username: String, password: String): Promise source
Starts replication to a remote database.
Emit:
* |
state(state): the state of the replicator. |
Private Methods
private _cancelCurrentReplicator() source
private _createReplicator(opts: Object): PouchDBReplicationID source
Creates a new PouchDB replicator. Remember that this class is simply a wrapper.
Return:
PouchDBReplicationID |