MCPcopy Index your code
hub / github.com/cloudtty/cloudtty / handleRequestQueue

Method handleRequestQueue

pkg/workerpool/worker_pool.go:245–286  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

243}
244
245func (w *WorkerPool) handleRequestQueue() {
246 w.Lock()
247 defer w.Unlock()
248 klog.V(4).InfoS("handle request queue")
249 for _, item := range w.requestQueue.All() {
250 req := item.(Request)
251 if _, err := w.matchWorkerFor(&req); err != nil {
252 if err != ErrNotWorker {
253 klog.ErrorS(err, "failed to create worker for cloudshell", req.Cloudshell)
254 }
255
256 pods, err := w.podLister.Pods(req.Namespace).List(labels.Set{constants.WorkerRequestLabelKey: req.Cloudshell}.AsSelector())
257 if err != nil {
258 klog.ErrorS(err, "failed to list worker for cloudshell", req.Cloudshell)
259 }
260
261 // TODO: pod is failed?
262
263 if len(pods) == 0 {
264 klog.InfoS("start to create worker", "cloudshell", req.Cloudshell)
265 if err := w.createWorker(&req); err != nil {
266 klog.ErrorS(err, "failed to create worker for cloudshell", req.Cloudshell)
267 }
268 }
269 } else {
270 cloudshell := &cloudshellv1alpha1.CloudShell{}
271 if err = w.Get(context.TODO(), client.ObjectKey{Namespace: req.Namespace, Name: req.Cloudshell}, cloudshell); err != nil {
272 if apierrors.IsNotFound(err) {
273 w.requestQueue.Remove(req)
274 }
275
276 klog.ErrorS(err, "failed to get cloudshell", req.Cloudshell)
277 continue
278 }
279
280 key, _ := cache.MetaNamespaceKeyFunc(cloudshell)
281 req.CloudShellQueue.Add(key)
282
283 w.requestQueue.Remove(req)
284 }
285 }
286}
287
288func (w *WorkerPool) tryScaleInWorkerQueue(stop <-chan struct{}) {
289 t := time.NewTicker(w.scaleInQueueDuration)

Callers 1

tryHandleRequestQueueMethod · 0.95

Calls 7

matchWorkerForMethod · 0.95
createWorkerMethod · 0.95
AllMethod · 0.65
ListMethod · 0.65
GetMethod · 0.65
RemoveMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected