import { access , ensureDir } from "fs-extra" ; import { dirname , join } from "path" ; import * as Logger from "../common/Logger" ; import QueueConfiguration from "./QueueConfiguration" ; import QueueEnvironment from "./QueueEnvironment" ; import QueueServer from "./QueueServer" ; import { DEFAULT_QUEUE_EXTENT_LOKI_DB_PATH , DEFAULT_QUEUE_LOKI_DB_PATH , DEFAULT_QUEUE_PERSISTENCE_ARRAY , DEFAULT_QUEUE_PERSISTENCE_PATH } from "./utils/constants" ; function shutdown ( server ) { const beforeCloseMessage = `Azurite Queue service is closing...` ; const afterCloseMessage = `Azurite Queue service successfully closed` ; console . log ( beforeCloseMessage ) ; server . close ( ) . then ( ( ) => { console . log ( afterCloseMessage ) ; } ) ; } /**
 * Entry for Azurite queue service.
 */ async function main ( ) { const env = new QueueEnvironment ( ) ; const location = await env . location ( ) ; await ensureDir ( location ) ; await access ( location ) ; const debugFilePath = await env . debug ( ) ; if ( debugFilePath !== undefined ) { await ensureDir ( dirname ( debugFilePath ! ) ) ; await access ( dirname ( debugFilePath ! ) ) ; } DEFAULT_QUEUE_PERSISTENCE_ARRAY [ 0 ] . locationPath = join ( location , DEFAULT_QUEUE_PERSISTENCE_PATH ) ; const config = new QueueConfiguration ( env . queueHost ( ) , env . queuePort ( ) , join ( location , DEFAULT_QUEUE_LOKI_DB_PATH ) , join ( location , DEFAULT_QUEUE_EXTENT_LOKI_DB_PATH ) , DEFAULT_QUEUE_PERSISTENCE_ARRAY , ! env . silent ( ) , undefined , ( await env . debug ( ) ) !== undefined , await env . debug ( ) , env . loose ( ) , env . skipApiVersionCheck ( ) , env . cert ( ) , env . key ( ) , env . pwd ( ) , env . oauth ( ) , env . disableProductStyleUrl ( ) ) ; Logger . configLogger ( config . enableDebugLog , config . debugLogFilePath ) ; const server = new QueueServer ( config ) ; console . log ( `Azurite Queue service is starting on ${ config . host }:${ config . port }` ) ; await server . start ( ) ; console . log ( `Azurite Queue service successfully listens on ${ server . getHttpServerAddress ( ) }` ) ; process . once ( "message" , ( msg ) => { if ( msg === "shutdown" ) { shutdown ( server ) ; } } ) . once ( "SIGINT" , ( ) => shutdown ( server ) ) . once ( "SIGTERM" , ( ) => shutdown ( server ) ) ; } main ( ) . catch ( ( err ) => { console . error ( `Exit due to unhandled error: ${ err . message }` ) ; process . exit ( 1 ) ; } ) ;