@@ -6,7 +6,7 @@ import { AddressInfo } from "net";
66import { Duplex } from "stream" ;
77
88import { CommunicationHandler , HostError , IDProvider } from "@scramjet/model" ;
9- import { HostHeaders , InstanceMessageCode , RunnerMessageCode , SequenceMessageCode } from "@scramjet/symbols" ;
9+ import { HostHeaders , InstanceMessageCode , InstanceStatus , RunnerMessageCode , SequenceMessageCode } from "@scramjet/symbols" ;
1010import {
1111 APIExpose ,
1212 CPMConnectorOptions ,
@@ -357,7 +357,7 @@ export class Host implements IComponent {
357357 await this . cpmConnector ?. sendInstanceInfo ( {
358358 id : instance . id ,
359359 sequence : instance . sequence
360- } , InstanceMessageCode . INSTANCE_CONNECTED ) ;
360+ } ) ;
361361
362362 this . pushTelemetry ( "Instance connected" , {
363363 id : instance . id ,
@@ -368,21 +368,22 @@ export class Host implements IComponent {
368368 /**
369369 * Pass information about ended instance to monitoring and platform services.
370370 *
371- * @param {DispatcherInstanceEndEventData } eventData Event details.
371+ * @param {DispatcherInstanceEndEventData } instance Event details.
372372 */
373- async handleDispatcherEndEvent ( eventData : DispatcherInstanceEndEventData ) {
374- this . auditor . auditInstance ( eventData . id , InstanceMessageCode . INSTANCE_ENDED ) ;
373+ async handleDispatcherEndEvent ( instance : DispatcherInstanceEndEventData ) {
374+ this . auditor . auditInstance ( instance . id , InstanceMessageCode . INSTANCE_ENDED ) ;
375375
376376 await this . cpmConnector ?. sendInstanceInfo ( {
377- id : eventData . id ,
378- sequence : eventData . sequence
379- } , InstanceMessageCode . INSTANCE_ENDED ) ;
377+ id : instance . id ,
378+ status : InstanceStatus . GONE ,
379+ sequence : instance . sequence
380+ } ) ;
380381
381382 this . pushTelemetry ( "Instance ended" , {
382- executionTime : eventData . info . executionTime . toString ( ) ,
383- id : eventData . id ,
384- code : eventData . code . toString ( ) ,
385- seqId : eventData . sequence . id
383+ executionTime : instance . info . executionTime . toString ( ) ,
384+ id : instance . id ,
385+ code : instance . code . toString ( ) ,
386+ seqId : instance . sequence . id
386387 } ) ;
387388 }
388389
@@ -1089,7 +1090,7 @@ export class Host implements IComponent {
10891090 try {
10901091 const runner = await this . csiDispatcher . startRunner ( sequence , payload ) ;
10911092
1092- if ( "id" in runner ) {
1093+ if ( runner && "id" in runner ) {
10931094 this . logger . debug ( "Instance limits" , runner . limits ) ;
10941095 this . auditor . auditInstanceStart ( runner . id , req as AuditedRequest , runner . limits ) ;
10951096 this . pushTelemetry ( "Instance started" , { id : runner . id , language : runner . sequence . config . language , seqId : runner . sequence . id } ) ;
@@ -1099,9 +1100,11 @@ export class Host implements IComponent {
10991100 message : `Sequence ${ runner . id } starting` ,
11001101 id : runner . id
11011102 } ;
1102- } else {
1103+ } else if ( runner ) {
11031104 throw runner ;
11041105 }
1106+
1107+ throw Error ( "Unexpected startup error" ) ;
11051108 } catch ( error : any ) {
11061109 this . pushTelemetry ( "Instance start failed" , { error : error . message } , "error" ) ;
11071110 this . logger . error ( error . message ) ;
0 commit comments