TaskAPI Smart Rules

TaskAPI Smart Rules are invoked interactively when a Task is moved in time or when one of its Workloads is moved across resources, they are specified through the API field of a Task.

Multiple Tasks can share the same TaskAPI (they just need to share the same URL), and TaskAPI are automatically loaded in a background tasks when loading a schedule.

Each TaskAPI is a JavaScript library, ideally name-spaced and fully private (when using SmartPascal, use a library rather than a program), and it must register a class implementing a TaskMoved method through the RegisterTaskAPI function.

TaskMoved method

The TaskMoved method receives four parameters:

  • jobID identifies the Job whose Task is affected
  • taskID identifies the Task which is affected
  • originalTaskData contains a copy of the Task data, in the Task format, with fields updated to current scheduling status
  • openings array holds for each Workload the Capacity Calendar the workloads are currently positioned on.

The Resources the Workloads are positioned on are listed in the originalTaskData structure, as that structure is updated before being passed to TaskMoved. Supplemental fields in the Task data structure are preserved and are passed as well.

If TaskMoved is successful and wants to effect changes, it should return true and apply the changes to originalTaskData, the following property changes are supported:

  • Duration
  • SetupDuration
  • Workloads Interrupts

The TaskMoved method will be called with a high frequency, implementations should aim to handle at least 300 calls per seconds (ie. be hable to move 10 Tasks at 30 frames per second), and ideally 1000 calls per second or more (to ensure smooth interactivity at 60 frames per second).

SmartPascal Scheduler.TaskAPI

unit Scheduler.TaskAPI;

type

   JSchedulerTaskAPI = class external

      // Triggered whenever the task is moved interactively
      // - jobName & taskName identify the task
      // - taskData contains normalized task JSON data structure
      // If the call changed the task data, the function should return 'true'
      function TaskMoved(jobID, taskID : String; taskData : Variant;
                         openings : array of array of array of Variant) : Variant;

   end;

procedure RegisterTaskAPI(api : JSchedulerTaskAPI); external 'window.RegisterTaskAPI';