node-appwrite
Version:
Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API
514 lines (447 loc) • 13.5 kB
JavaScript
const Service = require('../service.js');
const AppwriteException = require('../exception.js');
const InputFile = require('../inputFile.js');
const client = require('../client.js');
const Stream = require('stream');
const { promisify } = require('util');
const fs = require('fs');
const { File } = require('undici');
const Query = require('../query.js');
class Health extends Service {
constructor(client)
{
super(client);
}
/**
* Get HTTP
*
* Check the Appwrite HTTP server is up and responsive.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async get() {
const apiPath = '/health';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get antivirus
*
* Check the Appwrite Antivirus server is up and connection is successful.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async getAntivirus() {
const apiPath = '/health/anti-virus';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get cache
*
* Check the Appwrite in-memory cache servers are up and connection is
* successful.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async getCache() {
const apiPath = '/health/cache';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get the SSL certificate for a domain
*
* Get the SSL certificate for a domain
*
* @param {string} domain
* @throws {AppwriteException}
* @returns {Promise}
*/
async getCertificate(domain) {
const apiPath = '/health/certificate';
let payload = {};
if (typeof domain !== 'undefined') {
payload['domain'] = domain;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get DB
*
* Check the Appwrite database servers are up and connection is successful.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async getDB() {
const apiPath = '/health/db';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get pubsub
*
* Check the Appwrite pub-sub servers are up and connection is successful.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async getPubSub() {
const apiPath = '/health/pubsub';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get queue
*
* Check the Appwrite queue messaging servers are up and connection is
* successful.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueue() {
const apiPath = '/health/queue';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get builds queue
*
* Get the number of builds that are waiting to be processed in the Appwrite
* internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueBuilds(threshold) {
const apiPath = '/health/queue/builds';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get certificates queue
*
* Get the number of certificates that are waiting to be issued against
* [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue
* server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueCertificates(threshold) {
const apiPath = '/health/queue/certificates';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get databases queue
*
* Get the number of database changes that are waiting to be processed in the
* Appwrite internal queue server.
*
* @param {string} name
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueDatabases(name, threshold) {
const apiPath = '/health/queue/databases';
let payload = {};
if (typeof name !== 'undefined') {
payload['name'] = name;
}
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get deletes queue
*
* Get the number of background destructive changes that are waiting to be
* processed in the Appwrite internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueDeletes(threshold) {
const apiPath = '/health/queue/deletes';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get number of failed queue jobs
*
* Returns the amount of failed jobs in a given queue.
*
*
* @param {Name} name
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getFailedJobs(name, threshold) {
const apiPath = '/health/queue/failed/{name}'.replace('{name}', name);
let payload = {};
if (typeof name === 'undefined') {
throw new AppwriteException('Missing required parameter: "name"');
}
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get functions queue
*
* Get the number of function executions that are waiting to be processed in
* the Appwrite internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueFunctions(threshold) {
const apiPath = '/health/queue/functions';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get logs queue
*
* Get the number of logs that are waiting to be processed in the Appwrite
* internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueLogs(threshold) {
const apiPath = '/health/queue/logs';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get mails queue
*
* Get the number of mails that are waiting to be processed in the Appwrite
* internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueMails(threshold) {
const apiPath = '/health/queue/mails';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get messaging queue
*
* Get the number of messages that are waiting to be processed in the Appwrite
* internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueMessaging(threshold) {
const apiPath = '/health/queue/messaging';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get migrations queue
*
* Get the number of migrations that are waiting to be processed in the
* Appwrite internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueMigrations(threshold) {
const apiPath = '/health/queue/migrations';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get usage queue
*
* Get the number of metrics that are waiting to be processed in the Appwrite
* internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueUsage(threshold) {
const apiPath = '/health/queue/usage';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get usage dump queue
*
* Get the number of projects containing metrics that are waiting to be
* processed in the Appwrite internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueUsageDump(threshold) {
const apiPath = '/health/queue/usage-dump';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get webhooks queue
*
* Get the number of webhooks that are waiting to be processed in the Appwrite
* internal queue server.
*
* @param {number} threshold
* @throws {AppwriteException}
* @returns {Promise}
*/
async getQueueWebhooks(threshold) {
const apiPath = '/health/queue/webhooks';
let payload = {};
if (typeof threshold !== 'undefined') {
payload['threshold'] = threshold;
}
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get storage
*
* Check the Appwrite storage device is up and connection is successful.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async getStorage() {
const apiPath = '/health/storage';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get local storage
*
* Check the Appwrite local storage device is up and connection is successful.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async getStorageLocal() {
const apiPath = '/health/storage/local';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
/**
* Get time
*
* Check the Appwrite server time is synced with Google remote NTP server. We
* use this technology to smoothly handle leap seconds with no disruptive
* events. The [Network Time
* Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is
* used by hundreds of millions of computers and devices to synchronize their
* clocks over the Internet. If your computer sets its own clock, it likely
* uses NTP.
*
* @throws {AppwriteException}
* @returns {Promise}
*/
async getTime() {
const apiPath = '/health/time';
let payload = {};
return await this.client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);
}
}
module.exports = Health;