Class TaskScheduler

java.lang.Object
dev.frostlake.task.TaskScheduler

public class TaskScheduler extends Object
Schedules and executes tasks
  • Constructor Details

  • Method Details

    • currentTask

      public static Task currentTask()
      The task whose body is executing on the current thread, or null outside a task run.
    • schedulerKey

      public static String schedulerKey(String databaseName, String schemaName, String taskName)
      The scheduler key for a task: DB.SCHEMA.TASK, upper-cased. Every path that arms or cancels a task must build it the same way, or a later SUSPEND cancels nothing because it looks up a key that RESUME never wrote. Shared by ALTER TASK … RESUME/SUSPEND and by start()'s arming scan.
    • start

      public void start()
      Start the scheduler and arm every task already in the STARTED state.

      The scan matters because a task can reach STARTED without anyone calling resumeTask(java.lang.String, dev.frostlake.metastore.model.Task): a snapshot restore writes the state straight onto the model (CatalogSnapshotReader), so a task that was running when the engine was persisted comes back STARTED but unarmed, and would never fire again until it was manually RESUMEd. Arming here makes "it was running before the restart" survive the restart.

      Still OPT-IN — nothing starts the scheduler at engine boot, so an embedded engine spawns no timer threads unless the embedder asks for them (or a RESUME lazy-starts it).

    • stop

      public void stop()
    • scheduleTask

      public void scheduleTask(String qualifiedTaskName, Task task)
    • unscheduleTask

      public void unscheduleTask(String qualifiedTaskName)
    • resumeTask

      public void resumeTask(String qualifiedTaskName, Task task)
    • suspendTask

      public void suspendTask(String qualifiedTaskName, Task task)
    • executeTaskNow

      public void executeTaskNow(String qualifiedTaskName, Task task)
      Execute a task immediately (for testing)
    • executeTaskManually

      public void executeTaskManually(String qualifiedTaskName)
      Execute a task manually by name (for EXECUTE TASK command)
    • isRunning

      public boolean isRunning()
    • isScheduled

      public boolean isScheduled(String qualifiedTaskName)
      Whether this task currently holds a live timer entry. The key must be built with schedulerKey(java.lang.String, java.lang.String, java.lang.String); anything else answers false because it is not the key the scheduler armed under.
    • hasRunningExecutions

      public boolean hasRunningExecutions(String qualifiedTaskName)
      Whether a run of this task is in flight right now. Only tracked for tasks that forbid overlapping execution (the default) — a task with ALLOW_OVERLAPPING_EXECUTION = TRUE needs no in-flight bookkeeping, so it always reports false.