How to Abort All Queued Messages via Command Line
I'm working with IRIS for Health. I need to abort all messages currently in the queue via the command line (IRIS terminal). is there any easy way?
Comments
Hi @shima Avakh
Ens.Queueclass provides various methods for working with queues. Queue-related information is stored in the global^Ens.Queue. To abort messages from a specific queue, you can use the following class method
Do ##class(Ens.Queue).AbortQueue(pQueueName) Replace pQueueName with the name of the queue you want to abort. This method allows you to target and abort messages in a specific queue.
Thanks for the suggestion! Using Do ##class(Ens.Queue).AbortQueue("QueueName") works well for individual queues.
However, I'm looking for a way to abort all messages across all queues without having to specify each pQueueName one by one.
Here's a short method you can place in a utility class that does what you want:
ClassMethod AbortAll() As%Status
{
Set tSC = $$$OKSet tQry = ##class(%SQL.Statement).%New()
Set tSC = tQry.%PrepareClassQuery("Ens.Queue","Enumerate")
If$$$ISOK(tSC)
{
Set tRS = tQry.%Execute()
While tRS.%Next()
{
Set tQueue = tRS.%Get("Name")
Write !, "Aborting Queue "_tQueue
Do##class(Ens.Queue).AbortQueue(tQueue)
}
}
Return tSC
}
Also, one might be tempted to simply kill the ^Ens.Queue global.
Don't.
^Ens.Queue is used for other housekeeping tasks, and while killing it will absolutely remove all messages from visibility in the queue viewer, it won't change the message headers for those items from queued status to something else (like aborted or discarded). And it will very likely break other things that you really don't want to break.