How to get the Job id for a BS API Rest for debug?
Hi all,
As you know, it is very complicated to debug a Business Service Rest API because the object is created when the applications receive a request, so we cannot have the JobId that we can use to debug.
https://docs.intersystems.com/iris20211/csp/docbook/DocBook.UI.Page.cls?...
So, I'm trying to get the JobId when the class is being created, write a trace in OnInit() method and write the JobId in a log info
Method OnInit() As %Status
{
$$$LOGINFO("JobId: "_$JOB)
hang 20 break
Quit ..OnInit()
}
ObjectScriptObjectScript
Unfortunately, it seems to ignore this method because it doesn't show any traces or do the 20 seconds stop.
Then, my second attempt was to write it directly in the method.
/// MyMethod POST
ClassMethod MyMethodPost() As %Status
{
$$$LOGINFO("JobId: "_$JOB)
hang 20 break
.....
Quit $$$OK
}
ObjectScriptObjectScript
and it works, but I need 20 seconds to open Event Log, Get the JobId, attach the Id in Studio or VS Code and debug the code...
Maybe Superman can do it, with his super speed.
My cuestion is....
is it possible to have a hang instrucction by more time, but I can break the hang when I want?
Is there a common method (such as OnInit()) that is called when the application receives a request? I don't want to put this piece of code in all the methods of my API service.
Thanks in advance.
my private hack for this situation:
ClassMethod MyMethodPost() As %Status { $$$LOGINFO("JobId: "_$JOB) kill ^%kurro set ^%kurro(0)=$JOB for {hang 20 break quit:$get(^%kurro) } #; just hang around until ^%kurro =1 ..... Quit $$$OK }
Thanks for your answers. Good idea using a global as key to unlock the loop.
Just in case - I assume you know that nowadays, in VS Code, you have a very good and easy way to debug a REST Service, see the docs here.