@onlineapps/service-common
v1.0.5
Published
Common utilities for both infrastructure services and business services
Maintainers
Readme
@onlineapps/service-common
Common utilities for both infrastructure services and business services in OA Drive.
Purpose
This library provides shared functionality that is used across the entire system, by both infrastructure services (Gateway, Registry, Validator, etc.) and business services (hello-service, etc.).
Installation
npm install @onlineapps/service-commonUsage
Wait for Infrastructure Ready
Wait for all infrastructure services to be ready before creating queues:
Infrastructure Services:
const { waitForInfrastructureReady } = require('@onlineapps/service-common');
await waitForInfrastructureReady({
redisUrl: 'redis://api_node_cache:6379',
maxWait: 300000, // 5 minutes
checkInterval: 5000, // 5 seconds
logger: logger
});
// Now safe to create infrastructure queuesBusiness Services:
const { waitForInfrastructureReady } = require('@onlineapps/service-common');
await waitForInfrastructureReady({
redisUrl: process.env.REDIS_URL,
maxWait: 60000, // 1 minute
checkInterval: 5000, // 5 seconds
logger: logger
});
// Now safe to create business queuesAPI
waitForInfrastructureReady(options)
Waits for all infrastructure services to be reported as healthy by Registry.
Options:
redisUrl(string): Redis URL (default: from ENV orredis://api_node_cache:6379)maxWait(number): Maximum wait time in ms (default: 300000 = 5 minutes)checkInterval(number): Check interval in ms (default: 5000 = 5 seconds)logger(Object): Logger instance (default: console)
Returns: Promise<boolean> - True if all infrastructure services are ready
Throws: Error - If timeout is reached
Environment Variables:
REDIS_URL- Redis connection URLINFRASTRUCTURE_HEALTH_WAIT_MAX_TIME- Maximum wait time in msINFRASTRUCTURE_HEALTH_WAIT_CHECK_INTERVAL- Check interval in ms
Architecture
This library is used by:
- Infrastructure services (via
@onlineapps/infrastructure-toolswhich re-exports from here) - Business services (via
@onlineapps/service-wrapperor directly)
This ensures no duplication and consistent behavior across all services.
