Question
· Apr 11

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 properly
 set sc=wqm.Queue("subr1") ; executing the subr1 properly
 quit
subr1
 set ^test("subr1",$NOW())=$LB($USERNAME,$ROLES)
 quit
 ;
subr2()
 set ^test("subr2",$NOW())=$LB($USERNAME,$ROLES)
 quit

Thanks!

Product version: IRIS 2024.1
$ZV: IRIS for Windows (x86-64) 2024.1.1 (Build 347U) Thu Jul 18 2024 17:40:10 EDT
Discussion (3)2
Log in or sign up to continue

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.

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()) = ""
 quit

I 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!