}
public HistoryEvent createTaskInstanceCompleteEvt(DelegateTask task, String deleteReason) {
// create event instance
HistoricTaskInstanceEventEntity evt = loadTaskInstanceEvent(task);
// initialize event
initTaskInstanceEvent(evt, (TaskEntity) task, HistoryEventTypes.TASK_INSTANCE_COMPLETE);
// set end time
evt.setEndTime(ClockUtil.getCurrentTime());
if(evt.getStartTime() != null) {
evt.setDurationInMillis(evt.getEndTime().getTime()-evt.getStartTime().getTime());
}
// set delete reason
evt.setDeleteReason(deleteReason);
return evt;
}