@@ -21,7 +21,13 @@ import (
21
21
"encoding/json"
22
22
"errors"
23
23
"fmt"
24
+ "strconv"
25
+ "strings"
26
+ "sync"
27
+ "time"
28
+
24
29
"github.com/caarlos0/env/v6"
30
+ "github.com/devtron-labs/common-lib/async"
25
31
k8s2 "github.com/devtron-labs/common-lib/utils/k8s"
26
32
"github.com/devtron-labs/devtron/api/helm-app/service/bean"
27
33
"github.com/devtron-labs/devtron/internal/sql/models"
@@ -43,10 +49,6 @@ import (
43
49
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
44
50
"k8s.io/apimachinery/pkg/runtime"
45
51
"k8s.io/apimachinery/pkg/runtime/schema"
46
- "strconv"
47
- "strings"
48
- "sync"
49
- "time"
50
52
)
51
53
52
54
type UserTerminalAccessService interface {
@@ -75,6 +77,7 @@ type UserTerminalAccessServiceImpl struct {
75
77
terminalSessionHandler terminal.TerminalSessionHandler
76
78
K8sCapacityService capacity.K8sCapacityService
77
79
k8sUtil * k8s2.K8sServiceImpl
80
+ asyncRunnable * async.Runnable
78
81
}
79
82
80
83
type UserTerminalAccessSessionData struct {
@@ -98,7 +101,12 @@ func GetTerminalAccessConfig() (*models.UserTerminalSessionConfig, error) {
98
101
return config , err
99
102
}
100
103
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 ) {
102
110
//fetches all running and starting entities from db and start SyncStatus
103
111
podStatusSyncCron := cron .New (cron .WithChain (cron .Recover (cronLogger )))
104
112
terminalAccessDataArrayMutex := & sync.RWMutex {}
@@ -114,14 +122,15 @@ func NewUserTerminalAccessServiceImpl(logger *zap.SugaredLogger, terminalAccessR
114
122
terminalSessionHandler : terminalSessionHandler ,
115
123
K8sCapacityService : K8sCapacityService ,
116
124
k8sUtil : k8sUtil ,
125
+ asyncRunnable : asyncRunnable ,
117
126
}
118
127
podStatusSyncCron .Start ()
119
128
_ , err := podStatusSyncCron .AddFunc (fmt .Sprintf ("@every %ds" , config .TerminalPodStatusSyncTimeInSecs ), accessServiceImpl .SyncPodStatus )
120
129
if err != nil {
121
130
logger .Errorw ("error occurred while starting cron job" , "time in secs" , config .TerminalPodStatusSyncTimeInSecs )
122
131
return nil , err
123
132
}
124
- go accessServiceImpl .SyncRunningInstances ()
133
+ accessServiceImpl . asyncRunnable . Execute ( func () { accessServiceImpl .SyncRunningInstances () } )
125
134
return accessServiceImpl , err
126
135
}
127
136
func (impl * UserTerminalAccessServiceImpl ) ValidateShell (podName , namespace , shellName , containerName string , clusterId int ) (bool , string , error ) {
0 commit comments