Skip to content

Commit

Permalink
Implement support for unscheduling a Task.
Browse files Browse the repository at this point in the history
  • Loading branch information
sukritkalra committed Jan 16, 2024
1 parent 9bc043e commit 18ac808
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ def __create_events_from_task_placement_skip(
)
self._event_queue.remove_event(future_placement_event)
del self._future_placement_events[placement.task.id]

# Unschedule the Task.
placement.task.unschedule(time)
else:
self._logger.warning(
"[%s] Failed to place %s, skipping it for future reconsideration.",
Expand Down
28 changes: 28 additions & 0 deletions workload/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def __init__(
self._remaining_time = None
self._last_step_time = -1 # Time when this task was stepped through.
self._state = TaskState.VIRTUAL
self._pre_scheduling_state = TaskState.VIRTUAL
# ID of the worker pool on which the task is running.
self._worker_pool_id = None

Expand Down Expand Up @@ -184,6 +185,7 @@ def release(self, time: Optional[EventTime] = None):
f"{self.unique_name} from state {self._state}."
)
self._state = TaskState.RELEASED
self._pre_scheduling_state = TaskState.RELEASED

def schedule(
self,
Expand Down Expand Up @@ -225,6 +227,32 @@ def schedule(
self._worker_pool_id = placement.worker_pool_id
self.update_remaining_time(placement.execution_strategy.runtime)

def unschedule(
self,
time: EventTime,
) -> None:
"""Unschedules the execution of the task at the given simulator time.
Args:
time (`EventTime`): The simulation time at which the task was
unscheduled.
Raises:
`ValueError` if Task is not in `SCHEDULED` state yet.
"""
if self.state != TaskState.SCHEDULED:
raise ValueError(
f"Task must be in SCHEDULED state, currently in {self.state}."
)
self._logger.debug(
f"[{time.to(EventTime.Unit.US).time}] Transitioning {self} to "
f"{self._pre_scheduling_state} from {TaskState.SCHEDULED}."
)
self._state = self._pre_scheduling_state
self._scheduling_time = None
self._scheduler_placement = None
self._worker_pool_id = None

def start(
self,
time: Optional[EventTime] = None,
Expand Down

0 comments on commit 18ac808

Please sign in to comment.