Question
· Oct 4, 2018

Time Loop in Cache Object Script

Hello,

I am a beginner with Object Script and I hope anyone can help me solving my questions.

1. Is there a way to time a loop in Object Script? 

2. My code leads to the following error, even though it executes the method.

Is there a way to ignore this specific error, so that I can repeat my code in a time loop over and over again without stopping? 

<<THROW>%CreateProperty+85^%DocDB.Database.1 *%Exception.StatusException FEHLER #5805: Der ID-Schlüssel ist nicht eindeutig im Extent '%Dictionary.PropertyDefinition' : '^oddDEF("db.stream","a","Datum")' ist bereits vorhanden. Speicherort des ID-Zählers = ''>

Thank you in advance and best regards

Discussion (3)1
Log in or sign up to continue

Hi Tuan,

1. I'm not sure if you are asking for timed execution or benchmarking execution, so here is an answer to both.

For timed execution use the task manager...

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GSA_manage_taskmgr

For benchmarking a loop you will want to use $zh, its the most granular time function in COS, the docs here show it being used for benchmarking the execution of code...

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_vzhorolog

2. You will need to wrap your outer method call in a try catch block so that it will continue to repeat itself even if an error is thrown, something along the lines of...

ClassMethod Start()
{
    While 1 {
        try {
            do ..YourMainMethod()
        } catch err {
            //log error here
        }    
    }
}

More information can be found here...

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCOS_errors#GCOS_errors_ttc

Sean.

To implement a pause prior to continuing the loop, use the hang statement.

The code provided above is perfect for all the other requirement. After the closing bracket of the "catch", add "hang 10" for a ten second "sleep".

You should also add a mechanism to stop this iteration somehow. It will be good practice.

ClassMethod Start()
{

  
    While (^RunMyApp = 1) {
        try {
            do ..YourMainMethod()
        } catch err {
            //log error here
        }
        hang 10
    }

If you then want to stop your code from running, open another terminal or use the Management Portal and set the global value:
set ^RunMyApp = 0