chore: add qe and integrations with rabbit mq
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/rostpoliplast/backend/internal/mq"
|
||||
)
|
||||
|
||||
type QueueHandlers struct {
|
||||
MQ *mq.RabbitMQ
|
||||
}
|
||||
|
||||
func (h *QueueHandlers) RegisterRoutes(g *gin.RouterGroup) {
|
||||
g.GET("/queue/next", h.GetNextTask)
|
||||
}
|
||||
|
||||
// GetNextTask Получить следующую задачу из очереди
|
||||
// @Summary Получить следующую задачу из очереди
|
||||
// @Description Получает и удаляет из очереди следующую задачу (FIFO)
|
||||
// @Tags queue
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Success 404 {object} map[string]string
|
||||
// @Router /queue/next [get]
|
||||
func (h *QueueHandlers) GetNextTask(c *gin.Context) {
|
||||
if h.MQ == nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "rabbitmq not available"})
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.MQ.Consume()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "no messages in queue"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": string(data),
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user