All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.internal.ping-client.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InternalNodeGrpcPingClient = void 0;
const generated_types_1 = require("@gomomento/generated-types");
var grpcPing = generated_types_1.ping.cache_client;
const headers_interceptor_1 = require("./grpc/headers-interceptor");
const grpc_js_1 = require("@grpc/grpc-js");
const package_json_1 = require("../../package.json");
const idle_grpc_client_wrapper_1 = require("./grpc/idle-grpc-client-wrapper");
const retry_interceptor_1 = require("./grpc/retry-interceptor");
class InternalNodeGrpcPingClient {
    /**
     * @param {PingClientProps} props
     */
    constructor(props) {
        this.logger = props.configuration.getLoggerFactory().getLogger(this);
        const headers = [
            new headers_interceptor_1.Header('agent', `nodejs:ping:${package_json_1.version}`),
            new headers_interceptor_1.Header('runtime-version', `nodejs:${process.versions.node}`),
        ];
        this.interceptors = [
            headers_interceptor_1.HeaderInterceptor.createHeadersInterceptor(headers),
            retry_interceptor_1.RetryInterceptor.createRetryInterceptor({
                clientName: 'PingClient',
                loggerFactory: props.configuration.getLoggerFactory(),
                overallRequestTimeoutMs: InternalNodeGrpcPingClient.REQUEST_TIMEOUT_MS,
            }),
        ];
        this.logger.debug(`Creating ping client using endpoint: '${props.endpoint}`);
        this.clientWrapper = new idle_grpc_client_wrapper_1.IdleGrpcClientWrapper({
            clientFactoryFn: () => new grpcPing.PingClient(props.endpoint, props.credentialProvider.isCacheEndpointSecure()
                ? grpc_js_1.ChannelCredentials.createSsl()
                : grpc_js_1.ChannelCredentials.createInsecure()),
            loggerFactory: props.configuration.getLoggerFactory(),
            maxIdleMillis: props.configuration
                .getTransportStrategy()
                .getMaxIdleMillis(),
        });
    }
    async ping() {
        this.logger.info('pinging...');
        const request = new grpcPing._PingRequest();
        return await new Promise((resolve, reject) => {
            this.clientWrapper
                .getClient()
                // eslint-disable-next-line @typescript-eslint/no-unused-vars
                .Ping(request, { interceptors: this.interceptors }, (err, resp) => {
                if (err) {
                    this.logger.error('failed to ping');
                    reject(err);
                }
                else {
                    resolve();
                }
            });
        });
    }
}
exports.InternalNodeGrpcPingClient = InternalNodeGrpcPingClient;
InternalNodeGrpcPingClient.REQUEST_TIMEOUT_MS = 60 * 1000;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGluZy1jbGllbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvaW50ZXJuYWwvcGluZy1jbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsZ0VBQWdEO0FBQ2hELElBQU8sUUFBUSxHQUFHLHNCQUFJLENBQUMsWUFBWSxDQUFDO0FBQ3BDLG9FQUFxRTtBQUNyRSwyQ0FBOEQ7QUFDOUQscURBQTJDO0FBQzNDLDhFQUFzRTtBQUl0RSxnRUFBMEQ7QUFRMUQsTUFBYSwwQkFBMEI7SUFNckM7O09BRUc7SUFDSCxZQUFZLEtBQXNCO1FBQ2hDLElBQUksQ0FBQyxNQUFNLEdBQUcsS0FBSyxDQUFDLGFBQWEsQ0FBQyxnQkFBZ0IsRUFBRSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUNyRSxNQUFNLE9BQU8sR0FBRztZQUNkLElBQUksNEJBQU0sQ0FBQyxPQUFPLEVBQUUsZUFBZSxzQkFBTyxFQUFFLENBQUM7WUFDN0MsSUFBSSw0QkFBTSxDQUFDLGlCQUFpQixFQUFFLFVBQVUsT0FBTyxDQUFDLFFBQVEsQ0FBQyxJQUFJLEVBQUUsQ0FBQztTQUNqRSxDQUFDO1FBQ0YsSUFBSSxDQUFDLFlBQVksR0FBRztZQUNsQix1Q0FBaUIsQ0FBQyx3QkFBd0IsQ0FBQyxPQUFPLENBQUM7WUFDbkQsb0NBQWdCLENBQUMsc0JBQXNCLENBQUM7Z0JBQ3RDLFVBQVUsRUFBRSxZQUFZO2dCQUN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xuICAgICAgbG9nZ2VyRmFjdG9yeTogcHJvcHMuY29uZmlndXJhdGlvbi5nZXRMb2dnZXJGYWN0b3J5KCksXG4gICAgICBtYXhJZGxlTWlsbGlzOiBwcm9wcy5jb25maWd1cmF0aW9uXG4gICAgICAgIC5nZXRUcmFuc3BvcnRTdHJhdGVneSgpXG4gICAgICAgIC5nZXRNYXhJZGxlTWlsbGlzKCksXG4gICAgfSk7XG4gIH1cblxuICBwdWJsaWMgYXN5bmMgcGluZygpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICB0aGlzLmxvZ2dlci5pbmZvKCdwaW5naW5nLi4uJyk7XG4gICAgY29uc3QgcmVxdWVzdCA9IG5ldyBncnBjUGluZy5fUGluZ1JlcXVlc3QoKTtcbiAgICByZXR1cm4gYXdhaXQgbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgdGhpcy5jbGllbnRXcmFwcGVyXG4gICAgICAgIC5nZXRDbGllbnQoKVxuICAgICAgICAvLyBlc2xpbnQtZGlzYWJsZS1uZXh0LWxpbmUgQHR5cGVzY3JpcHQtZXNsaW50L25vLXVudXNlZC12YXJzXG4gICAgICAgIC5QaW5nKHJlcXVlc3QsIHtpbnRlcmNlcHRvcnM6IHRoaXMuaW50ZXJjZXB0b3JzfSwgKGVyciwgcmVzcCkgPT4ge1xuICAgICAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgICAgIHRoaXMubG9nZ2VyLmVycm9yKCdmYWlsZWQgdG8gcGluZycpO1xuICAgICAgICAgICAgcmVqZWN0KGVycik7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJlc29sdmUoKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH0pO1xuICB9XG59XG4iXX0=




© 2015 - 2024 Weber Informatics LLC | Privacy Policy