'Returns all queued SpecialTasks prioritized for repair first, then
cleanup, then verify.'

def _get_prioritized_special_tasks(self):

    queued_tasks = models.SpecialTask.objects.filter(is_active=False, is_complete=False, host__locked=False)
    queued_tasks = models.SpecialTask.objects.add_join(queued_tasks, 'afe_host_queue_entries', 'host_id', join_condition='afe_host_queue_entries.active', join_from_key='host_id', force_left_join=True)
    queued_tasks = queued_tasks.extra(where=['(afe_host_queue_entries.id    IS    NULL    OR    afe_host_queue_entries.id    =    afe_special_tasks.queue_entry_id)'])
    task_priority_order = [models.SpecialTask.Task.REPAIR, models.SpecialTask.Task.CLEANUP, models.SpecialTask.Task.VERIFY]
    def task_priority_key(task):
        return task_priority_order.index(task.task)
    return sorted(queued_tasks, key=task_priority_key)
