@@ -9,6 +9,7 @@ import { type DequeuedMessage } from "@trigger.dev/core/v3";
99import {
1010 DockerResourceMonitor ,
1111 KubernetesResourceMonitor ,
12+ NoopResourceMonitor ,
1213 type ResourceMonitor ,
1314} from "./resourceMonitor.js" ;
1415import { KubernetesWorkloadManager } from "./workloadManager/kubernetes.js" ;
@@ -69,6 +70,16 @@ class ManagedSupervisor {
6970 dockerAutoremove : env . RUNNER_DOCKER_AUTOREMOVE ,
7071 } satisfies WorkloadManagerOptions ;
7172
73+ this . resourceMonitor = env . RESOURCE_MONITOR_ENABLED
74+ ? this . isKubernetes
75+ ? new KubernetesResourceMonitor ( createK8sApi ( ) , env . TRIGGER_WORKER_INSTANCE_NAME )
76+ : new DockerResourceMonitor ( new Docker ( ) )
77+ : new NoopResourceMonitor ( ) ;
78+
79+ this . workloadManager = this . isKubernetes
80+ ? new KubernetesWorkloadManager ( workloadManagerOptions )
81+ : new DockerWorkloadManager ( workloadManagerOptions ) ;
82+
7283 if ( this . isKubernetes ) {
7384 if ( env . POD_CLEANER_ENABLED ) {
7485 this . logger . log ( "🧹 Pod cleaner enabled" , {
@@ -99,15 +110,6 @@ class ManagedSupervisor {
99110 } else {
100111 this . logger . warn ( "Failed pod handler disabled" ) ;
101112 }
102-
103- this . resourceMonitor = new KubernetesResourceMonitor (
104- createK8sApi ( ) ,
105- env . TRIGGER_WORKER_INSTANCE_NAME
106- ) ;
107- this . workloadManager = new KubernetesWorkloadManager ( workloadManagerOptions ) ;
108- } else {
109- this . resourceMonitor = new DockerResourceMonitor ( new Docker ( ) ) ;
110- this . workloadManager = new DockerWorkloadManager ( workloadManagerOptions ) ;
111113 }
112114
113115 this . workerSession = new SupervisorSession ( {
@@ -123,12 +125,17 @@ class ManagedSupervisor {
123125 runNotificationsEnabled : env . TRIGGER_WORKLOAD_API_ENABLED ,
124126 heartbeatIntervalSeconds : env . TRIGGER_WORKER_HEARTBEAT_INTERVAL_SECONDS ,
125127 preDequeue : async ( ) => {
128+ if ( ! env . RESOURCE_MONITOR_ENABLED ) {
129+ return { } ;
130+ }
131+
126132 if ( this . isKubernetes ) {
127133 // Not used in k8s for now
128134 return { } ;
129135 }
130136
131137 const resources = await this . resourceMonitor . getNodeResources ( ) ;
138+
132139 return {
133140 maxResources : {
134141 cpu : resources . cpuAvailable ,
0 commit comments