Subroutine execution issues in WorkMgr
Hello Community,
The subroutine ^routine is not executed while the queue is being processed in WorkMgr. However, it works when defined as a function. Is it mandatory to define subroutine^routine as a function for it to execute properly?
testwqm.mac
set wqm = ##class(%SYSTEM.WorkMgr).%New()
set sc=wqm.Queue("subr1^testwqm") ; not executing the subr1 set sc=wqm.Queue("subr2^testwqm") ; executing the subr2 properlyset sc=wqm.Queue("subr1") ; executing the subr1 properlyquit
subr1
set^test("subr1",$NOW())=$LB($USERNAME,$ROLES)
quit;
subr2()
set^test("subr2",$NOW())=$LB($USERNAME,$ROLES)
quitThanks!
Comments
Yes this is true and a formal way to do this is really the thing you queue, whether a function or a class method should return a %Status to signal to the wqm that an error occured. In practice the usage of wqm.Queue should not only call a function or class method but pass some parameters. I often times have my function/class method act on a collection/list of rowids so my call to .Queue includes the function/classmethod as well as the list of rowids to process.
Hi Ashok,
For the queue manager to recognize a proper completion of any code, it should be defined as a function.
If you test the sc for subr1 you will see a <PARAMETER> error. This is why the () is required.
It is better to have a quit $$$OK (or Quit 1) at the end, but this is not mandatory.
Hello @Yaron Munz
Calling the label or subroutine directly without specifying the routine name—for example, set sc=wqm.Queue("subr1")—always works. However, using the label^routine syntax does not work as expected. If I need to execute a subroutine from a different routine, I have to wrap that subroutine inside another function and call that function instead.
test.mac
set wqm = ##class(%SYSTEM.WorkMgr).%New()
set sc = wqm.Queue("f1^test1")
quit;
test1.mac
;
f1()
do subr1
quit
subr1
set^test($NOW()) = ""quitI agree that return values are always not required when executing a routine, even when using methods like wqm.WaitForComplete() or wqm.Sync(). However, return values are mandatory for class when use wqm.WaitForComplete() or wqm.Sync().
Class
When invoking class methods, you can call them with or without parameters, and with or without return values. Return values are not required if you don't need to capture the status using wqm.WaitForComplete() or wqm.Sync()
Set wqm = ##class(%SYSTEM.WorkMgr).%New()
Set sc=wqm.Queue("..func1",1)
Set sc=wqm.Queue("##Class(Sample.Person).func1")return values required if the status by using "wqm.WaitForComplete()" or "wqm.Sync()"
Set wqm = ##class(%SYSTEM.WorkMgr).%New()
Set sc=wqm.Queue("..func1",1)
Set sc=wqm.Queue("##Class(Sample.Person).func1",1)
Set sc=wqm.WaitForComplete()
If ('sc) W$SYSTEM.OBJ.DisplayError(sc)thanks!