// Complete the stats
taskInfo.setEndTime(new NSTimestamp());
taskInfo.setWorkflowState(TaskInfo.WORKFLOW_PROCESSING_COMPLETE);
long duration = taskInfo.endTime().getTime() - taskInfo.startTime().getTime();
taskInfo.setDuration(duration);
ec.saveChanges();
} finally {