GetUsageQueue pops queued usage records from the usage queue.
(c *gin.Context)
| 22 | |
| 23 | // GetUsageQueue pops queued usage records from the usage queue. |
| 24 | func (h *Handler) GetUsageQueue(c *gin.Context) { |
| 25 | if h == nil { |
| 26 | c.JSON(http.StatusInternalServerError, gin.H{"error": "handler unavailable"}) |
| 27 | return |
| 28 | } |
| 29 | |
| 30 | count, errCount := parseUsageQueueCount(c.Query("count")) |
| 31 | if errCount != nil { |
| 32 | c.JSON(http.StatusBadRequest, gin.H{"error": errCount.Error()}) |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | items := redisqueue.PopOldest(count) |
| 37 | records := make([]usageQueueRecord, 0, len(items)) |
| 38 | for _, item := range items { |
| 39 | records = append(records, usageQueueRecord(append([]byte(nil), item...))) |
| 40 | } |
| 41 | |
| 42 | c.JSON(http.StatusOK, records) |
| 43 | } |
| 44 | |
| 45 | func parseUsageQueueCount(value string) (int, error) { |
| 46 | value = strings.TrimSpace(value) |