MongoDatabaseClient
MongoDB database client.
Exported in @perseid/jobs/mongodb
.
Extends @perseid/jobs
DatabaseClient
class.
constructor
Class constructor.
public constructor(
logger: Logger,
cache: CacheClient,
settings: DatabaseClientSettings,
);
Parameters
- logger: Logging system to use.
- cache: Cache client instance to use for results caching.
- settings: Database client settings.
Usage
const databaseClient = new MongoDatabaseClient(logger, cache, {
host: 'mongodb',
port: 27017,
user: null,
password: null,
protocol: 'mongodb:',
database: 'test',
connectTimeout: 2000,
connectionLimit: 10,
})
formatTasks
Formats results
into a database-agnostic tasks.
protected formatTasks(results: unknown[]): DataModel['tasks'][];
Parameters
- results: List of database raw results to format.
Returns
Formatted results.
Usage
databaseClient.formatTasks([...]);
updateMatchingTask
Updates task that matches filters
with payload
.
public abstract updateMatchingTask(
filters: SearchFilters,
payload: Payload<DataModel['tasks']>,
): Promise<boolean>;
Parameters
- filters: Filters to apply to match task.
- payload: Updated task payload.
Returns
true
if task was updated, false
otherwise.
Usage
databaseClient.updateMatchingTask({
_id: new Id(),
_status: 'IN_PROGRESS'
}, { _status: 'COMPLETED' });
getRunningTasks
Fetches list of running tasks.
public abstract getRunningTasks(): Promise<DataModel['tasks'][]>;
Returns
Running tasks list.
Usage
await databaseClient.getRunningTasks(); // [...]
getCandidatePendingTasks
Fetches the list of pending tasks that are candidate for execution.
public abstract getCandidatePendingTasks(): Promise<DataModel['tasks'][]>;
Returns
Pending tasks list.
Usage
await databaseClient.getCandidatePendingTasks(); // [...]