Skip to content

Task Scheduler

This page introduces the KXS Task Scheduler service class, which manages background and time-dependent recurring task execution.

KX Sensors includes a core service called the Task Scheduler, which manages the execution of background and time-dependent operations. It provides a flexible and reliable mechanism for scheduling and executing recurring tasks.

Tasks are launched as NTASKs from the Task Scheduler service class. This service class should be configured within your node manifest:

services:
  - sc: TS
    enabled: true
    portOffset: 0
    num: 1
    prefix: ""
    threads: 0
    taskset: ""
    tls: 0
    auth: false

Once the Task Scheduler service is started and tasks are properly defined in configuration, NTASKs are launched automatically at their configured times. If a task fails to start, the framework automatically retries it.

Configuration

Scheduled tasks are configured via the file config/taskScheduler.yaml.

The parameters for controlling scheduled tasks are defined in the meta file meta/taskScheduler.yaml:

taskSchedule:
  m-description: Configures the KX Sensors task scheduler service
  values:
    m-type: dict
    m-required: true
    m-value:
      startTS:
        m-type: timestamp
        m-description: Time at which to dispatch the scheduled task, in UTC
        m-required: true
      freq:
        m-type: integer
        m-description: Frequency at which to dispatch the scheduled task, in minutes
        m-required: true
      load:
        m-type: symbols
        m-description: Scripts to load on the scheduled task
        m-required: true
      init:
        m-type: symbol
        m-description: Monadic initialization function to run on the scheduled task
        m-required: true
      enabled:
        m-type: boolean
        m-description: Indicates whether or not the scheduled task is enabled
        m-required: true

The Task Scheduler periodically checks whether tasks are ready to dispatch. This period is defined in config/systemParams.yaml:

- name: tsChkFreq
  type: int
  description: Interval (in seconds) used to check if scheduled tasks are ready to dispatch
  value: 60
  dynamic: false

Sample configuration

The following example shows a configuration bundled with the core product. It defines the archiver task, which performs compression and deletion of aged KX Sensors application log files:

taskSchedule:
  values:
    <default>:
      startTS: 00:00:00
      freq: 1440
      enabled: true
    archiver:
      load: [ src/task/archiver.q ]
      init: .archiver.run

In this configuration:

  • The <default> key defines default values for all tasks, including:
    • startTS: tasks run at UTC midnight.
    • freq: tasks run once daily.
    • enabled: tasks are enabled.
  • The archiver task:
    • Loads the script src/task/archiver.q.
    • Executes the function .archiver.run when dispatched.

Next steps