@@ -652,7 +652,7 @@ type ServerCommand =
652652 | { type : "isopen" ; content : { file : string } }
653653 | { type : "stop" ; content : empty }
654654 | { type : "isready" ; content : empty }
655- | { type : "workers " ; content : empty } ;
655+ | { type : "status " ; content : empty } ;
656656
657657async function writeJuliaCommand (
658658 conn : Deno . Conn ,
@@ -829,13 +829,6 @@ function populateJuliaEngineCommand(command: Command) {
829829 return ;
830830}
831831
832- type WorkerStatus = {
833- path : string ;
834- run_started ?: string ;
835- run_finished ?: string ;
836- timeout : number ;
837- } ;
838-
839832async function logStatus ( ) {
840833 const transportFile = juliaTransportFile ( ) ;
841834 if ( ! existsSync ( transportFile ) ) {
@@ -850,103 +843,19 @@ async function logStatus() {
850843 ) ;
851844 const successfullyConnected = typeof conn !== "string" ;
852845
853- info (
854- `Julia server is${ successfullyConnected ? "" : " not" } responding.
855- port: ${ transportOptions . port }
856- pid: ${ transportOptions . pid }
857- julia version: ${ transportOptions . juliaVersion }
858- environment: ${ transportOptions . environment }
859- runner version: ${ transportOptions . runnerVersion } ` ,
860- ) ;
861-
862846 if ( successfullyConnected ) {
863- const workers = await writeJuliaCommand (
847+ const status : string = await writeJuliaCommand (
864848 conn ,
865- { type : "workers " , content : { } } ,
849+ { type : "status " , content : { } } ,
866850 transportOptions . key ,
867851 { } as JuliaExecuteOptions ,
868- ) as WorkerStatus [ ] ;
869- info ( ` workers active: ${ workers . length } ` ) ;
870- workers . forEach ( ( worker , index ) => {
871- const runStarted = ! worker . run_started
872- ? undefined
873- : new Date ( worker . run_started ) ;
874- const runFinished = ! worker . run_finished
875- ? undefined
876- : new Date ( worker . run_finished ) ;
877-
878- const secondsSinceStarted = runStarted !== undefined
879- ? ( Date . now ( ) - runStarted . getTime ( ) ) / 1000
880- : undefined ;
881- const runDurationSeconds =
882- runStarted !== undefined && runFinished !== undefined
883- ? ( runFinished . getTime ( ) - runStarted . getTime ( ) ) / 1000
884- : undefined ;
885- const secondsSinceFinished = runFinished !== undefined
886- ? ( Date . now ( ) - runFinished . getTime ( ) ) / 1000
887- : undefined ;
888- const timeUntilTimeout =
889- worker . timeout > 0 && secondsSinceFinished !== undefined
890- ? worker . timeout - secondsSinceFinished
891- : undefined ;
892-
893- info (
894- ` worker ${ index + 1 } :
895- path: ${ worker . path }
896- run started: ${ runStarted ? simpleDateTimeString ( runStarted ) : "-" } ${
897- secondsSinceStarted
898- ? ` (${ formatSeconds ( secondsSinceStarted ) } ago)`
899- : ""
900- }
901- run finished: ${ runFinished ? simpleDateTimeString ( runFinished ) : "-" } ${
902- runDurationSeconds
903- ? ` (took ${ formatSeconds ( runDurationSeconds ) } )`
904- : ""
905- }
906- timeout: ${ worker . timeout } seconds ${
907- timeUntilTimeout ? `(${ formatSeconds ( timeUntilTimeout ) } left)` : ""
908- }
909- ` ,
910- ) ;
911- } ) ;
912- conn . close ( ) ;
913- }
914- }
915-
916- function isSameDay ( date1 : Date , date2 : Date ) : boolean {
917- return (
918- date1 . getFullYear ( ) === date2 . getFullYear ( ) &&
919- date1 . getMonth ( ) === date2 . getMonth ( ) &&
920- date1 . getDate ( ) === date2 . getDate ( )
921- ) ;
922- }
852+ ) ;
923853
924- function simpleDateTimeString ( date : Date ) {
925- const now = new Date ( ) ;
926- return isSameDay ( date , now )
927- ? date . toLocaleTimeString ( )
928- : `${ date . toLocaleDateString ( ) } ${ date . toLocaleTimeString ( ) } ` ;
929- }
854+ Deno . stdout . writeSync ( ( new TextEncoder ( ) ) . encode ( status ) ) ;
930855
931- function formatSeconds ( seconds : number ) : string {
932- seconds = Math . round ( seconds ) ;
933- if ( seconds < 60 ) {
934- const s = seconds == 1 ? "" : "s" ;
935- return `${ seconds } second${ s } ` ;
936- } else if ( seconds < 3600 ) {
937- const rem_seconds = seconds % 60 ;
938- const full_minutes = ( seconds - rem_seconds ) / 60 ;
939- const s = full_minutes == 1 ? "" : "s" ;
940- const seconds_str = rem_seconds == 0
941- ? ""
942- : ` ${ formatSeconds ( rem_seconds ) } ` ;
943- return `${ full_minutes } minute${ s } ${ seconds_str } ` ;
856+ conn . close ( ) ;
944857 } else {
945- const rem_seconds = seconds % 3600 ;
946- const full_hours = ( seconds - rem_seconds ) / 3600 ;
947- const s = full_hours == 1 ? "" : "s" ;
948- const minutes_str = rem_seconds == 0 ? "" : ` formatSeconds(rem_seconds)` ;
949- return `${ full_hours } hour${ s } ${ minutes_str } ` ;
858+ info ( `Found transport file but can't connect to control server.` ) ;
950859 }
951860}
952861
0 commit comments