String newestTask = Iterables.getLast(Sets.newTreeSet(activeTasksInShard));
if (Tasks.id(task).equals(newestTask)) {
LOG.info("Retaining task " + Tasks.id(task));
} else {
task.setStatus(ScheduleStatus.KILLED);
task.addToTaskEvents(new TaskEvent(clock.nowMillis(), ScheduleStatus.KILLED)
.setMessage("Killed duplicate shard."));
// TODO(wfarner); Circle back if this is necessary. Currently there's a race
// condition between the time the scheduler is actually available without hitting
// IllegalStateException (see DriverImpl).
// driver.killTask(Tasks.id(task));