TaskQueue

class dias.TaskQueue(tasks)

Bases: object

The dias task queue.

The TaskQueue contains the list of all tasks to be executed by the scheduler. It uses threading.Lock to ensure thread-safety.

Hint

Tasks in the task queue can be accessed as if they were in a list:

queue[key] or queue[slice]

The first task in the queue, (queue[0]), is the next to be scheduled. Use len to find the number of tasks in the queue:

len(queue)

Adding or removing elements from the queue is not supported.

Methods

next_task(self) Get the next task to be scheduled.
next_time(self) Get the start time of the next task to be scheduled.
sort(self) Sort the task queue.
update(self, task) Update the task queue for a new start time of task.

Construct the task queue.

Parameters:tasks (dict) – A dict of Task instances to be taken care of by the scheduler. The keys are the task names (String).

Methods

next_task(self) Get the next task to be scheduled.
next_time(self) Get the start time of the next task to be scheduled.
sort(self) Sort the task queue.
update(self, task) Update the task queue for a new start time of task.

Methods Summary

next_task(self) Get the next task to be scheduled.
next_time(self) Get the start time of the next task to be scheduled.
sort(self) Sort the task queue.
update(self, task) Update the task queue for a new start time of task.

Methods Documentation

next_task(self)

Get the next task to be scheduled.

Note

self.next_task() is equivalent to self[0].

Returns:Task – The next task in the queue.
next_time(self)

Get the start time of the next task to be scheduled.

Returns:datetime.datetime – The start time of the next task in the queue.
sort(self)

Sort the task queue.

After sorting, the next task to schedule will be first. Really, once sorted, the queue stays sorted, so this function needs only be called by the constructor when the queue is first made.

update(self, task)

Update the task queue for a new start time of task.

Increment the start time of task by its period and then relocate it in the queue to keep the task queue sorted.

Parameters:task (Task) – The task to update in the queue.