Task Queues

0
hi,I have built an app in order to know the working of Task Queues in the Mendix, but not able to run the task queue feature in it.Don't know the reasons behind it because there are no errors. please need help hereDomain Model I am using two microflows 1. Main MicroflowCreating the ImportTaskQueue and calling the submicroflow by mentioning to execute in the Task Queue.2. Sub Microflow -> for which the task queue is attachedHere the REST API call is implemented to fetch data as a single task for the individual threads, the API endPoint is handled in such a way that each task is different in terms of limit and offset for fecthing the data (Products). Dashboard of the App
asked
1 answers
0

Hi,


Your task queue setup itself looks fine. The problem is in the main microflow,

the part after the while loop where you check if all tasks are done and loop

back when they are not.


A microflow called with "Execute in a task queue" does not start at that

moment. Mendix only puts the task in the queue when the transaction of the

calling microflow has finished. So while your main microflow sits in that

check loop, none of the tasks have started, CompletedTasks stays 0, and the

loop keeps waiting for something that can only begin after the microflow

ends. That is why you get no error, it just never moves.


How I would change it:


1. Main microflow: clean old data, create the ImportTask objects, call

ACT_ProcessImportTask in the queue for each one, set the job status to

Running, commit, and end. No waiting, no end time, no log there.


2. Move the "is everything done" check to the end of ACT_ProcessImportTask.

After a task sets its own status, retrieve from database the ImportTasks

of that job that are still Pending/Running. If the count is 0, set the

ImportJob to Completed and set the end time there.


3. Don't increase CompletedTasks / FailedTasks on the ImportJob from inside

the tasks. If your queue has more than 1 thread, two tasks can read the

same value and both write +1, so you lose counts. Better to count the

ImportTask objects by status when you need the numbers (aggregate list on

a database retrieve), or show the tasks in a list on the page.


4. To see what really happened with the tasks, add a page on

System.ProcessedQueueTask (or use the Task Queue Helpers module from the

Marketplace). Failed tasks show there with the error message. Errors from

queue tasks never pop up in the browser, so this is where to look. You can

also set the TaskQueue log node to Trace.


5. The dashboard will not refresh on its own because the work happens in the

background. Use the refresh button or a timer on the page to reload the

job and products.


One more thing: parameters passed to a queue microflow must be committed

objects. Your ImportJob and ImportTask are committed before the call so that

part is ok, just keep it that way.


I hope this helps resolve the issue. If this solution works for you, please consider accepting this answer as the accepted solution.

answered