or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Task Scheduler with Historical Timing

Build a task execution system that schedules tasks intelligently based on their historical execution times to optimize overall completion time.

Requirements

Your system must track task execution history and use this data to optimize scheduling of future task runs.

Task Tracking

  • Each task has a unique identifier and can depend on other tasks
  • Track the execution duration for each task run
  • Maintain historical timing data across multiple executions
  • Calculate average execution times from historical data

Intelligent Scheduling

  • When multiple tasks are ready to execute (all dependencies satisfied), prioritize longer-running tasks first
  • Use historical average execution times to determine task priority
  • For tasks with no execution history, assign a default estimated time
  • Schedule tasks to minimize total completion time when running in parallel

Execution Engine

  • Execute tasks in topological order (dependencies before dependents)
  • Support parallel execution of independent tasks
  • Respect task dependencies - a task cannot start until all its dependencies complete
  • Record actual execution time after each task completes

Test Cases

  • Given a task that has never run before, it should be assigned the default estimated execution time. @test
  • Given a task that has run multiple times, its priority should be based on the average of historical execution times. @test
  • Given multiple independent tasks, longer-running tasks (based on historical data) should be scheduled before shorter ones. @test
  • Given a task graph with dependencies, tasks should execute only after all dependencies complete. @test

Implementation

@generates

API

interface TaskDefinition {
  id: string;
  execute: () => Promise<void>;
  dependencies?: string[];
}

interface ExecutionRecord {
  taskId: string;
  duration: number;
  timestamp: Date;
}

class TaskScheduler {
  /**
   * Creates a new task scheduler with a default estimated execution time
   * for tasks with no historical data.
   */
  constructor(defaultEstimatedTime: number);

  /**
   * Records the execution of a task and its duration in milliseconds.
   */
  recordExecution(taskId: string, duration: number): void;

  /**
   * Gets the estimated execution time for a task based on historical data.
   * Returns the average of all recorded executions, or the default if no history exists.
   */
  getEstimatedTime(taskId: string): number;

  /**
   * Schedules and executes tasks in optimized order based on historical timing.
   * Returns execution records for all completed tasks.
   */
  executeTasks(tasks: TaskDefinition[]): Promise<ExecutionRecord[]>;
}

Dependencies { .dependencies }

nx { .dependency }

Provides intelligent task scheduling and execution capabilities.