fix: don't need acks on queue checks (#926)

This commit is contained in:
abelanger5
2024-10-01 20:52:02 -04:00
committed by GitHub
parent c29984305e
commit c3fa2c57f3
5 changed files with 27 additions and 9 deletions

View File

@@ -136,6 +136,9 @@ type Message struct {
// RetryDelay is the delay between retries.
RetryDelay int `json:"retry_delay"`
// Whether the message should immediately expire if it reaches the queue without an active consumer.
ImmediatelyExpire bool `json:"immediately_expire"`
// OtelCarrier is the OpenTelemetry carrier for the task.
OtelCarrier map[string]string `json:"otel_carrier"`
}

View File

@@ -341,9 +341,15 @@ func (t *MessageQueueImpl) startPublishing() func() error {
t.l.Debug().Msgf("publishing msg %s to queue %s", msg.ID, msg.q.Name())
err = pub.PublishWithContext(ctx, "", msg.q.Name(), false, false, amqp.Publishing{
pubMsg := amqp.Publishing{
Body: body,
})
}
if msg.ImmediatelyExpire {
pubMsg.Expiration = "0"
}
err = pub.PublishWithContext(ctx, "", msg.q.Name(), false, false, pubMsg)
// retry failed delivery on the next session
if err != nil {

View File

@@ -116,7 +116,7 @@ func (q *queue) Start() (func() error, error) {
q.s.Start()
f := func(task *msgqueue.Message) error {
postAck := func(task *msgqueue.Message) error {
wg.Add(1)
defer wg.Done()
@@ -129,7 +129,11 @@ func (q *queue) Start() (func() error, error) {
return nil
}
cleanupQueue, err := q.mq.Subscribe(msgqueue.QueueTypeFromPartitionIDAndController(q.p.GetControllerPartitionId(), msgqueue.JobController), f, msgqueue.NoOpHook)
cleanupQueue, err := q.mq.Subscribe(
msgqueue.QueueTypeFromPartitionIDAndController(q.p.GetControllerPartitionId(), msgqueue.JobController),
msgqueue.NoOpHook, // the only handler is to check the queue, so we acknowledge immediately with the NoOpHook
postAck,
)
if err != nil {
cancel()

View File

@@ -267,7 +267,11 @@ func (wc *WorkflowsControllerImpl) Start() (func() error, error) {
return nil
}
cleanupQueue2, err := wc.mq.Subscribe(msgqueue.QueueTypeFromPartitionIDAndController(wc.p.GetControllerPartitionId(), msgqueue.WorkflowController), f2, msgqueue.NoOpHook)
cleanupQueue2, err := wc.mq.Subscribe(
msgqueue.QueueTypeFromPartitionIDAndController(wc.p.GetControllerPartitionId(), msgqueue.WorkflowController),
msgqueue.NoOpHook, // the only handler is to check the queue, so we acknowledge immediately with the NoOpHook
f2,
)
if err != nil {
cancel()

View File

@@ -40,10 +40,11 @@ func CheckTenantQueueToTask(tenantId string) *msgqueue.Message {
})
return &msgqueue.Message{
ID: "check-tenant-queue",
Payload: nil,
Metadata: metadata,
Retries: 3,
ID: "check-tenant-queue",
Payload: nil,
Metadata: metadata,
ImmediatelyExpire: true,
Retries: 3,
}
}