Files
order-notification-automation/tests/fixtures/startup-failure-service.cjs
T

14 lines
954 B
JavaScript

'use strict';
const fs=require('node:fs'),http=require('node:http');
const {respondToPing}=require('../../src/platform/service/ping.cjs');
const file=process.env.ORDER_FIXTURE_COUNT;
fs.writeFileSync(file,String((fs.existsSync(file)?Number(fs.readFileSync(file,'utf8')):0)+1));
if(!fs.existsSync(file+'.ready')){
process.send({type:'order:startup-failed',diagnostic:{type:'Error',stage:'key_directory',code:'STORAGE_UNAVAILABLE',causeCode:'ETIMEDOUT',durationMs:30000,message:'SECRET_FIXTURE_NOT_FOR_STATE'}});
process.exitCode=1;
}else{
const server=http.createServer((request,response)=>respondToPing(request,response,{token:process.env.ORDER_SUPERVISOR_TOKEN,instanceId:process.env.ORDER_SUPERVISOR_INSTANCE,startedAt:new Date().toISOString()}));
server.listen(Number(process.env.ORDER_FIXTURE_PORT),'127.0.0.1');
process.on('message',message=>{if(message==='order:shutdown'){server.closeAllConnections();server.close(()=>process.exit(0));}});
}