For the scenario when we need to know who has completed a certain task in the process before we have used a Task Listener for event type assignment with inline groovy script
task.execution.setVariable('managerId', task.assignee);
If the database update has to be performed once the task is completed the same approach can be taken by to use complete event and Java class as listener.