Fix consumed instruction ordering and clear history
This commit is contained in:
@@ -106,14 +106,21 @@ func handleDeleteInstruction(stores Stores, broker *events.Broker) http.HandlerF
|
||||
|
||||
func handleClearConsumed(stores Stores, broker *events.Broker) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
items, err := stores.Instructions.List("consumed")
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := stores.Instructions.DeleteConsumed(); err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
counts, _ := stores.Instructions.Counts()
|
||||
broker.Broadcast("history.cleared", nil)
|
||||
cleared := len(items)
|
||||
broker.Broadcast("history.cleared", map[string]any{"count": cleared})
|
||||
broker.Broadcast("status.changed", map[string]any{"queue": counts})
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
writeJSON(w, http.StatusOK, map[string]any{"cleared": cleared})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user