Question
· Aug 5

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?

Discussion (4)2
Log in or sign up to continue

Hi @shima Avakh 

Ens.Queue class provides various methods for working with queues. Queue-related information is stored in the global ^Ens.QueueTo 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.

Here's a short method you can place in a utility class that does what you want:

ClassMethod AbortAll() As %Status
{
    Set tSC = $$$OK
    Set 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.