@@ -56,6 +56,8 @@ const Env = z.object({
5656 TRIGGER_WORKER_INSTANCE_NAME : z . string ( ) ,
5757 TRIGGER_HEARTBEAT_INTERVAL_SECONDS : z . coerce . number ( ) . default ( 30 ) ,
5858 TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS : z . coerce . number ( ) . default ( 5 ) ,
59+ TRIGGER_SUCCESS_EXIT_CODE : z . coerce . number ( ) . default ( 0 ) ,
60+ TRIGGER_FAILURE_EXIT_CODE : z . coerce . number ( ) . default ( 1 ) ,
5961} ) ;
6062
6163const env = Env . parse ( stdEnv ) ;
@@ -82,6 +84,8 @@ type Metadata = {
8284 TRIGGER_WORKER_INSTANCE_NAME : string | undefined ;
8385 TRIGGER_HEARTBEAT_INTERVAL_SECONDS : number | undefined ;
8486 TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS : number | undefined ;
87+ TRIGGER_SUCCESS_EXIT_CODE : number | undefined ;
88+ TRIGGER_FAILURE_EXIT_CODE : number | undefined ;
8589} ;
8690
8791class MetadataClient {
@@ -122,6 +126,9 @@ class ManagedRunController {
122126 private workerApiUrl : string ;
123127 private workerInstanceName : string ;
124128
129+ private successExitCode = env . TRIGGER_SUCCESS_EXIT_CODE ;
130+ private failureExitCode = env . TRIGGER_FAILURE_EXIT_CODE ;
131+
125132 private state :
126133 | {
127134 phase : "RUN" ;
@@ -665,6 +672,14 @@ class ManagedRunController {
665672
666673 logger . log ( "Processing env overrides" , { env : overrides } ) ;
667674
675+ if ( overrides . TRIGGER_SUCCESS_EXIT_CODE ) {
676+ this . successExitCode = overrides . TRIGGER_SUCCESS_EXIT_CODE ;
677+ }
678+
679+ if ( overrides . TRIGGER_FAILURE_EXIT_CODE ) {
680+ this . failureExitCode = overrides . TRIGGER_FAILURE_EXIT_CODE ;
681+ }
682+
668683 if ( overrides . TRIGGER_HEARTBEAT_INTERVAL_SECONDS ) {
669684 this . heartbeatIntervalSeconds = overrides . TRIGGER_HEARTBEAT_INTERVAL_SECONDS ;
670685 this . runHeartbeat . updateInterval ( this . heartbeatIntervalSeconds * 1000 ) ;
@@ -817,7 +832,7 @@ class ManagedRunController {
817832
818833 if ( ! this . warmStartClient ) {
819834 console . error ( "waitForNextRun: warm starts disabled, shutting down" ) ;
820- this . exitProcess ( 0 ) ;
835+ this . exitProcess ( this . successExitCode ) ;
821836 }
822837
823838 // Check the service is up and get additional warm start config
@@ -828,7 +843,7 @@ class ManagedRunController {
828843 warmStartUrl : env . TRIGGER_WARM_START_URL ,
829844 error : connect . error ,
830845 } ) ;
831- this . exitProcess ( 0 ) ;
846+ this . exitProcess ( this . successExitCode ) ;
832847 }
833848
834849 const connectionTimeoutMs =
@@ -856,7 +871,7 @@ class ManagedRunController {
856871 connectionTimeoutMs,
857872 keepaliveMs,
858873 } ) ;
859- this . exitProcess ( 0 ) ;
874+ this . exitProcess ( this . successExitCode ) ;
860875 }
861876
862877 const nextRun = await this . warmStartClient . warmStart ( {
@@ -867,7 +882,7 @@ class ManagedRunController {
867882
868883 if ( ! nextRun ) {
869884 console . error ( "waitForNextRun: warm start failed, shutting down" ) ;
870- this . exitProcess ( 0 ) ;
885+ this . exitProcess ( this . successExitCode ) ;
871886 }
872887
873888 console . log ( "waitForNextRun: got next run" , { nextRun } ) ;
@@ -880,7 +895,7 @@ class ManagedRunController {
880895 return ;
881896 } catch ( error ) {
882897 console . error ( "waitForNextRun: unexpected error" , { error } ) ;
883- this . exitProcess ( 1 ) ;
898+ this . exitProcess ( this . failureExitCode ) ;
884899 } finally {
885900 this . waitForNextRunLock = false ;
886901 }
0 commit comments