@@ -21,7 +21,13 @@ import (
2121	"encoding/json" 
2222	"errors" 
2323	"fmt" 
24+ 	"strconv" 
25+ 	"strings" 
26+ 	"sync" 
27+ 	"time" 
28+ 
2429	"github.com/caarlos0/env/v6" 
30+ 	"github.com/devtron-labs/common-lib/async" 
2531	k8s2 "github.com/devtron-labs/common-lib/utils/k8s" 
2632	"github.com/devtron-labs/devtron/api/helm-app/service/bean" 
2733	"github.com/devtron-labs/devtron/internal/sql/models" 
@@ -43,10 +49,6 @@ import (
4349	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
4450	"k8s.io/apimachinery/pkg/runtime" 
4551	"k8s.io/apimachinery/pkg/runtime/schema" 
46- 	"strconv" 
47- 	"strings" 
48- 	"sync" 
49- 	"time" 
5052)
5153
5254type  UserTerminalAccessService  interface  {
@@ -75,6 +77,7 @@ type UserTerminalAccessServiceImpl struct {
7577	terminalSessionHandler        terminal.TerminalSessionHandler 
7678	K8sCapacityService            capacity.K8sCapacityService 
7779	k8sUtil                       * k8s2.K8sServiceImpl 
80+ 	asyncRunnable                 * async.Runnable 
7881}
7982
8083type  UserTerminalAccessSessionData  struct  {
@@ -98,7 +101,12 @@ func GetTerminalAccessConfig() (*models.UserTerminalSessionConfig, error) {
98101	return  config , err 
99102}
100103
101- func  NewUserTerminalAccessServiceImpl (logger  * zap.SugaredLogger , terminalAccessRepository  repository.TerminalAccessRepository , config  * models.UserTerminalSessionConfig , k8sCommonService  k8s.K8sCommonService , terminalSessionHandler  terminal.TerminalSessionHandler , K8sCapacityService  capacity.K8sCapacityService , k8sUtil  * k8s2.K8sServiceImpl , cronLogger  * cron3.CronLoggerImpl ) (* UserTerminalAccessServiceImpl , error ) {
104+ func  NewUserTerminalAccessServiceImpl (logger  * zap.SugaredLogger ,
105+ 	terminalAccessRepository  repository.TerminalAccessRepository ,
106+ 	config  * models.UserTerminalSessionConfig , k8sCommonService  k8s.K8sCommonService ,
107+ 	terminalSessionHandler  terminal.TerminalSessionHandler ,
108+ 	K8sCapacityService  capacity.K8sCapacityService , k8sUtil  * k8s2.K8sServiceImpl ,
109+ 	cronLogger  * cron3.CronLoggerImpl , asyncRunnable  * async.Runnable ) (* UserTerminalAccessServiceImpl , error ) {
102110	//fetches all running and starting entities from db and start SyncStatus 
103111	podStatusSyncCron  :=  cron .New (cron .WithChain (cron .Recover (cronLogger )))
104112	terminalAccessDataArrayMutex  :=  & sync.RWMutex {}
@@ -114,14 +122,15 @@ func NewUserTerminalAccessServiceImpl(logger *zap.SugaredLogger, terminalAccessR
114122		terminalSessionHandler :       terminalSessionHandler ,
115123		K8sCapacityService :           K8sCapacityService ,
116124		k8sUtil :                      k8sUtil ,
125+ 		asyncRunnable :                asyncRunnable ,
117126	}
118127	podStatusSyncCron .Start ()
119128	_ , err  :=  podStatusSyncCron .AddFunc (fmt .Sprintf ("@every %ds" , config .TerminalPodStatusSyncTimeInSecs ), accessServiceImpl .SyncPodStatus )
120129	if  err  !=  nil  {
121130		logger .Errorw ("error occurred while starting cron job" , "time in secs" , config .TerminalPodStatusSyncTimeInSecs )
122131		return  nil , err 
123132	}
124- 	go   accessServiceImpl .SyncRunningInstances ()
133+ 	accessServiceImpl . asyncRunnable . Execute ( func () {  accessServiceImpl .SyncRunningInstances () } )
125134	return  accessServiceImpl , err 
126135}
127136func  (impl  * UserTerminalAccessServiceImpl ) ValidateShell (podName , namespace , shellName , containerName  string , clusterId  int ) (bool , string , error ) {
0 commit comments