package.dist.src.internal.ping-client.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk Show documentation
Show all versions of sdk Show documentation
Client SDK for Momento services
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");
const utils_1 = require("@gomomento/sdk-core/dist/src/utils");
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 = (0, utils_1.secondsToMilliseconds)(60);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGluZy1jbGllbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvaW50ZXJuYWwvcGluZy1jbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsZ0VBQWdEO0FBQ2hELElBQU8sUUFBUSxHQUFHLHNCQUFJLENBQUMsWUFBWSxDQUFDO0FBQ3BDLG9FQUFxRTtBQUNyRSwyQ0FBOEQ7QUFDOUQscURBQTJDO0FBQzNDLDhFQUFzRTtBQUl0RSxnRUFBMEQ7QUFDMUQsOERBQXlFO0FBUXpFLE1BQWEsMEJBQTBCO0lBT3JDOztPQUVHO0lBQ0gsWUFBWSxLQUFzQjtRQUNoQyxJQUFJLENBQUMsTUFBTSxHQUFHLEtBQUssQ0FBQyxhQUFhLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDckUsTUFBTSxPQUFPLEdBQUc7WUFDZCxJQUFJLDRCQUFNLENBQUMsT0FBTyxFQUFFLGVBQWUsc0JBQU8sRUFBRSxDQUFDO1lBQzdDLElBQUksNEJBQU0sQ0FBQyxpQkFBaUIsRUFBRSxVQUFVLE9BQU8sQ0FBQyxRQUFRLENBQUMsSUFBSSxFQUFFLENBQUM7U0FDakUsQ0FBQztRQUNGLElBQUksQ0FBQyxZQUFZLEdBQUc7WUFDbEIsdUNBQWlCLENBQUMsd0JBQXdCLENBQUMsT0FBTyxDQUFDO1lBQ25ELG9DQUFnQixDQUFDLHNCQUFzQixDQUFDO2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2x2ZSgpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfSk7XG4gIH1cbn1cbiJdfQ==
© 2015 - 2025 Weber Informatics LLC | Privacy Policy