Written by

Senior Software Engineer
Question Ashok Kumar T · Apr 29

WorkMgr execution issues

Hello Community,

I have a queue that I need to traverse and perform operations on. To distribute the workload across multiple processes, I used a Work Queue Manager do process and I'm not expecting any status from it So, I skipped Sync / WaitForComplete in my implementation

When I execute the below code. Lot of queues are not processed properly. If I add a 0.1-second delay, it works as expected. Is there a minimum time required for a process to start after it's added to the Queue

ClassMethod CleanUpQWrkMgr()
{
    Set QueueId=""Set workMgr = ##class(%SYSTEM.WorkMgr).%New()
    If workMgr=""quitfor {
        Set QueueId = $O(^Q(QueueId),1,data),event=""q:QueueId=""Do workMgr.Queue("..Cleanup",QueueId)
        //h .1	
    }
    //Set st= workMgr.WaitForComplete()
}

ClassMethod Cleanup(QueueId As%Integer)
{
    Set event=""For {
            Set event = $Order(^Q(QueueId,event)),rev=""Q:event=""For {
                Set rev = $Order(^Q(QueueId,event,rev)) Q:rev=""If '$Data(^DQ(rev,"e",event))
                Do$I(CNT)
            }
    }
    Set^test("CNT",QueueId)=CNT
    Quit1
}

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

Comments

Yaron Munz · Apr 29

Ashok,
I recommend that You have:
Set sc = workMgr.Queue("..Cleanup",QueueId)
and also:
Set sc = workMgr.WaitForComplete() 
Do
workMgr.Clear()
All this will ensure a relegable and smooth completion of the queue manager.
We never used any hung when adding tasks into the queue.

0
Ashok Kumar T  Apr 29 to Yaron Munz

Hello @Yaron Munz 

I’m using Set sc = workMgr.Queue("..Cleanup", QueueId). I intentionally commented out Set sc = workMgr.WaitForComplete() because I'm not concerned (for now) with the completion status. Is it mandatory to include WaitForComplete()/Sync() when working with WorkMgr?

0
Mark Hanson  May 5 to Ashok Kumar T

Normally it is required that you call the Sync/WaitForCompelete method on the work queue object so that the module can report errors and you can introduce a sync point where you know that the work done by the worker tasks has completed.

If you do not call Sync/WaitForComplete then what is likely happening if your work queue oref is going out of scope at the end of your procedure which closes the oref and this terminates all work units in this work queue group so if they have not completed at this point they will never get run as the entire queue is removed.

0
Ashok Kumar T  May 6 to Mark Hanson

Thank you, @Mark Hanson — your explanation clarified my question. Once the object goes out of scope(removed from memory) / reference count drops to zero the entire queue is deleted. Therefore, using Sync/WaitForComplete is essential to ensure the work is properly completed.

0