From 8bdca09b7bf859cd0510a723ec68bfebd7169261 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Wed, 8 Feb 2023 19:42:21 +0100 Subject: [PATCH] on admin index page, show number of messages in queue next to link to the queue list --- http/admin.go | 7 +++++++ http/admin.html | 7 +++++-- http/adminapi.json | 13 +++++++++++++ queue/queue.go | 5 +++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/http/admin.go b/http/admin.go index b1e03cf..4c16caf 100644 --- a/http/admin.go +++ b/http/admin.go @@ -1447,6 +1447,13 @@ func (Admin) QueueList(ctx context.Context) []queue.Msg { return l } +// QueueSize returns the number of messages currently in the outgoing queue. +func (Admin) QueueSize(ctx context.Context) int { + n, err := queue.Count() + xcheckf(ctx, err, "listing messages in queue") + return n +} + // QueueKick initiates delivery of a message from the queue. func (Admin) QueueKick(ctx context.Context, id int64) { n, err := queue.Kick(id, "", "") diff --git a/http/admin.html b/http/admin.html index 9521752..79bb9a2 100644 --- a/http/admin.html +++ b/http/admin.html @@ -188,7 +188,10 @@ const formatSize = n => { } const index = async () => { - const domains = await api.Domains() + const [domains, queueSize] = await Promise.all([ + await api.Domains(), + await api.QueueSize(), + ]) let fieldset, domain, account, localpart @@ -197,7 +200,7 @@ const index = async () => { crumbs('Mox Admin'), dom.p( dom.a('Accounts', attr({href: '#accounts'})), dom.br(), - dom.a('Queue', attr({href: '#queue'})), dom.br(), + dom.a('Queue', attr({href: '#queue'})), ' ('+queueSize+')', dom.br(), ), dom.h2('Domains'), domains.length === 0 ? box(red, 'No domains') : diff --git a/http/adminapi.json b/http/adminapi.json index 4bbef9b..462ce65 100644 --- a/http/adminapi.json +++ b/http/adminapi.json @@ -552,6 +552,19 @@ } ] }, + { + "Name": "QueueSize", + "Docs": "QueueSize returns the number of messages currently in the outgoing queue.", + "Params": [], + "Returns": [ + { + "Name": "r0", + "Typewords": [ + "int32" + ] + } + ] + }, { "Name": "QueueKick", "Docs": "QueueKick initiates delivery of a message from the queue.", diff --git a/queue/queue.go b/queue/queue.go index 9838659..4513ece 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -162,6 +162,11 @@ func List() ([]Msg, error) { return qmsgs, nil } +// Count returns the number of messages in the delivery queue. +func Count() (int, error) { + return bstore.QueryDB[Msg](queueDB).Count() +} + // Add a new message to the queue. The queue is kicked immediately to start a // first delivery attempt. //