Class TaskQueue

java.lang.Object
io.jenkins.tools.pluginmodernizer.tui.task.TaskQueue
All Implemented Interfaces:
AutoCloseable

public final class TaskQueue extends Object implements AutoCloseable
Run tasks one at a time, in queue order, on a single background thread.

Log lines are routed to the running task. One task runs at a time because the core services share one configuration and are not safe for concurrent plugin processing.

  • Constructor Details

    • TaskQueue

      public TaskQueue()
  • Method Details

    • submit

      public Task submit(String name, Callable<Boolean> work)
      Add a task at the end of the queue
      Parameters:
      name - name displayed in the task list
      work - returns true on success
      Returns:
      the queued task
    • restart

      public Optional<Task> restart(Task task)
      Queue a finished task again as a new task with the same name and work
      Parameters:
      task - the finished task
      Returns:
      the new task, or empty if the task is queued or running
    • log

      public void log(String line)
      Append a log line to the running task, or to the global logs when the queue is idle
      Parameters:
      line - the formatted line
    • tasks

      public List<Task> tasks()
      Returns:
      all tasks, in queue order
    • running

      public Optional<Task> running()
    • count

      public long count(TaskStatus status)
    • globalLogs

      public LogBuffer globalLogs()
    • cancel

      public boolean cancel(Task task)
      Skip a queued task, or ask a running task to stop. The core does not check interruptions, so a running task may keep working until its plugin is processed.
      Parameters:
      task - the task
      Returns:
      false if the task is already done
    • remove

      public boolean remove(Task task)
      Remove a queued or finished task from the list
      Parameters:
      task - the task
      Returns:
      false if the task is running
    • clearFinished

      public int clearFinished()
      Remove all finished tasks
      Returns:
      the number of removed tasks
    • move

      public boolean move(Task task, int delta)
      Swap a queued task with the previous or next queued task
      Parameters:
      task - the queued task
      delta - negative to run it earlier, positive to run it later
      Returns:
      true if the task moved
    • shutdown

      public boolean shutdown(Duration timeout)
      Skip queued tasks, interrupt the running one and wait for it to stop
      Parameters:
      timeout - maximum time to wait
      Returns:
      true if the worker stopped in time
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable