Преглед изворни кода

Add a repair status to the ETL status, and enhance blocking queue with a TryDequeue() method for non-blocking dequeue and Clear() for resetting the queue contents.

Matt Bolt пре 4 година
родитељ
комит
0b1b81427a
2 измењених фајлова са 25 додато и 0 уклоњено
  1. 24 0
      pkg/collections/blockingqueue.go
  2. 1 0
      pkg/kubecost/status.go

+ 24 - 0
pkg/collections/blockingqueue.go

@@ -17,6 +17,11 @@ type BlockingQueue interface {
 	// Dequeue removes the first item from the queue and returns it.
 	Dequeue() interface{}
 
+	// TryDequeue attempts to remove the first item from the queue and return it. This
+	// method does not block, and instead, returns true if the item was available and false
+	// otherwise
+	TryDequeue() (interface{}, bool)
+
 	// Each blocks modification and allows iteration of the queue.
 	Each(f func(int, interface{}))
 
@@ -73,6 +78,25 @@ func (q *blockingSliceQueue) Dequeue() interface{} {
 	return e
 }
 
+// TryDequeue attempts to remove the first item from the queue and return it. This
+// method does not block, and instead, returns true if the item was available and false
+// otherwise
+func (q *blockingSliceQueue) TryDequeue() (interface{}, bool) {
+	q.l.Lock()
+	defer q.l.Unlock()
+
+	if len(q.q) == 0 {
+		return nil, false
+	}
+
+	e := q.q[0]
+
+	// nil 0 index to prevent leak
+	q.q[0] = nil
+	q.q = q.q[1:]
+	return e, true
+}
+
 // Each blocks modification and allows iteration of the queue.
 func (q *blockingSliceQueue) Each(f func(int, interface{})) {
 	q.l.Lock()

+ 1 - 0
pkg/kubecost/status.go

@@ -29,6 +29,7 @@ type FileStatus struct {
 	Name         string            `json:"name"`
 	Size         string            `json:"size"`
 	LastModified time.Time         `json:"lastModified"`
+	IsRepairing  bool              `json:"isRepairing"`
 	Details      map[string]string `json:"details,omitempty"`
 	Errors       []string          `json:"errors,omitempty"`
 	Warnings     []string          `json:"warnings,omitempty"`