Notifications
Clear all

[Solved] Callback after transaction commit?

3 Posts
3 Users
0 Likes
2,584 Views
0
Topic starter

I have some code which I want to run at the conclusion of a workflow to decouple the processing from the UI user request-response cycle.

This should be straight-forward using a grid task. So at the end of my action workflow I have some code which does this:

public class InsertOrUpdateFromInterface extends AbstractActionBasedWorkflowActivity {
  ...
  public void execute(ActionBasedWorkflowContext context) {
    ...
    GridService gridService = Services.get(GridService.class);
    GridTask task = gridService.newTask(TASK_TYPE);
    task.setParams(createTaskParams(ctx).toString());
    gridService.queueTasks(QUEUE_NAME, ListUtil.create(task));
    ...
  }
}

Does GridService.queueTasks() run in its own transaction and commit immediately, or does it use the workflow's transaction?

I'm assuming it uses it's own transaction because the grid task is getting executed before the workflow and callback chain completes. 

For this requirement I need the grid task to run after the transaction commits. I thought I could do this in a Callback but it looks as though all of the methods execute within the context of the workflow/callback chain transaction. So the same issue.

How do I get the grid task to execute only after the commit has been performed?

3 Answers
0

GridService.queueTasks() should run in the current transaction, i.e. it should not commit until the overall workflow write commits.    The new grid task shouldn't be accessible to grid threads until the acion-based workflow is completely done.  

We depend on this logic in many, many places in the code.  So i feel like there must be something else special about your flow, if you're seeing the task run before the action-based workflow is done.

Maybe you can put a breakpoint right after the grid enqueue, and send us a picture of the stack trace?  I'm wondering if somewhere in the overall flow there could be a "callInNewTransaction" type of call that is spawning this.

0
Topic starter

I tracked the issue down to a problem in my code. As mentioned in the answer, the creation of the grid task is committed along with the surrounding transaction from the workflow which is required behavior.

0

I narrowed the problem down to a flaw in my code. The development of the grid task is committed along with the surrounding transaction from the workflow, as stated in the response, which is necessary behaviour.