Assignment
Description
Write a small task scheduling (cron-like) application that allows the user (the developer) to register tasks to be executed at certain moments in time, or based on certain temporal patterns.
Requirements
Each task is characterized by the following:
a type as one of:
immediate -- a task that shall be executed as soon as possible;
delayed -- a task that shall be executed once after a certain amount of time; the task has also a property that specifies the delayed time;
iterative -- a task that shall be executed for an infinite number of times after a certain interval of time; the task has a property that specifies the interval;
a priority that specifies the importance of the task; if two tasks are to be executed at the same time, then the one with the highest priority is chosen;
- the code that has to be executed;
Assumptions:
- we don't take into account the time the task takes to execute, thus tasks could be delayed from their schedule;
- we also assume that the system is not indefinitely overflown with tasks -- i.e. there are going to be periods in which no task is to be executed, thus the first one to be scheduled is not delayed;
Provide the developer with a library that allows the following operations:
- enqueue tasks;
- cancel tasks;
- trigger the task execution -- we assume that the library doesn't own a thread, but from time to time it is called by the user to execute the tasks that are due or scheduled at the moment of the call;
all operations must be re-entrant -- as the consequence of the execution of a scheduled task, new tasks might be enqueued or canceled (thus the call stack might look like this: (<trigger-task-execution> / ... / <enqueue-task>);