Skip to main content

CursesMonitor

A curses based Celery task monitor.

Attributes

AttributeTypeDescription
keymapdict = {}Mapping of keyboard characters to handler methods used for processing user input.
winwindow = nullThe curses window object used for all screen drawing and input operations.
screen_delayint = 10The duration in milliseconds to pause between screen updates during the nap cycle.
selected_taskstring = nullThe UUID of the currently highlighted task in the monitor interface.
selected_positionint = 0The numerical index of the currently selected row in the task list.
selected_strstring = Selected:The prefix label displayed in the footer when showing details for a selected task.
foregroundint = curses.COLOR_BLACKThe curses color constant used for the primary text color of the interface.
backgroundint = curses.COLOR_WHITEThe curses color constant used for the background color of the interface.
online_strstring = Workers online:The label used in the footer to introduce the list of active workers.
help_titlestring = Keys:The label used to introduce the keyboard shortcut help section in the footer.
helpstring = j:down k:up i:info t:traceback r:result c:revoke ^c: quitVerbatim string describing available key bindings shown at the bottom of the screen.
greetstring = celery events {VERSION_BANNER}The greeting message and version banner displayed at the top of the monitor.
info_strstring = Info:The label used to introduce the general status information line in the footer.
keyaliasdict = {curses.KEY_DOWN: 'J', curses.KEY_UP: 'K', curses.KEY_ENTER: 'I'}Mapping of curses key constants to their equivalent character representations for unified input handling.

Constructor

Signature

def CursesMonitor(
state: Any,
app: [Celery](../../app/base/celery.md?sid=celery_app_base_celery),
keymap: dict = None
) - > null

Parameters

NameTypeDescription
stateAnyThe current state of the Celery workers and tasks.
app[Celery](../../app/base/celery.md?sid=celery_app_base_celery)The Celery application instance.
keymapdict = NoneOptional dictionary mapping keys to handler methods to override or extend default behavior.

Methods


format_row()

@classmethod
def format_row(
uuid: string,
task: string,
worker: string,
timestamp: string,
state: string
) - > string

Formats a single task row for display, calculating column widths based on the current screen dimensions.

Parameters

NameTypeDescription
uuidstringThe unique identifier of the task.
taskstringThe name of the task.
workerstringThe hostname of the worker executing the task.
timestampstringThe formatted time string for the task event.
statestringThe current execution state of the task.

Returns

TypeDescription
stringA formatted string containing the task UUID, worker, name, timestamp, and state, truncated to fit the display width.

screen_width()

@classmethod
def screen_width() - > integer

Retrieves the total width of the current curses window.

Returns

TypeDescription
integerThe maximum number of columns available in the window.

screen_height()

@classmethod
def screen_height() - > integer

Retrieves the total height of the current curses window.

Returns

TypeDescription
integerThe maximum number of rows available in the window.

display_width()

@classmethod
def display_width() - > integer

Calculates the usable width for task data, accounting for border spacing.

Returns

TypeDescription
integerThe width available for content after subtracting border offsets.

display_height()

@classmethod
def display_height() - > integer

Calculates the usable height for the task list, reserving space for headers and footers.

Returns

TypeDescription
integerThe number of rows available to display task entries.

limit()

@classmethod
def limit() - > integer

Determines the maximum number of tasks that can be displayed on the current screen.

Returns

TypeDescription
integerThe display height limit for the task list.

find_position()

@classmethod
def find_position() - > integer

Locates the index of the currently selected task within the visible task list.

Returns

TypeDescription
integerThe zero-based index of the selected task, or 0 if no task is selected or found.

move_selection_up()

@classmethod
def move_selection_up()

Moves the UI selection highlight to the previous task in the list.


move_selection_down()

@classmethod
def move_selection_down()

Moves the UI selection highlight to the next task in the list.


move_selection()

@classmethod
def move_selection(
direction: integer
)

Updates the selected task by shifting the current position by a specified direction.

Parameters

NameTypeDescription
directionintegerThe number of positions to move; positive for down, negative for up.

handle_keypress()

@classmethod
def handle_keypress()

Reads a key from the curses window and executes the corresponding command from the keymap.


alert()

@classmethod
def alert(
callback: callable,
title: string
) - > string

Displays a temporary modal-like screen with a title and custom content, waiting for a keypress to dismiss.

Parameters

NameTypeDescription
callbackcallableA function used to render the body of the alert; receives max_y, max_x, and starting y-coordinate.
titlestringThe header text displayed at the top of the alert screen.

Returns

TypeDescription
stringThe uppercase string representation of the key pressed to exit the alert.

selection_rate_limit()

@classmethod
def selection_rate_limit()

Prompts the user for a new rate limit and applies it to the currently selected task's type.


alert_remote_control_reply()

@classmethod
def alert_remote_control_reply(
reply: list
) - > string

Displays an alert showing the responses received from workers after a remote control command.

Parameters

NameTypeDescription
replylistA list of dictionaries containing worker hostnames and their respective command responses.

Returns

TypeDescription
stringThe key pressed to dismiss the alert.

readline()

@classmethod
def readline(
x: integer,
y: integer
) - > string

Captures a line of text input from the user at a specific screen location.

Parameters

NameTypeDescription
xintegerThe vertical row coordinate where input starts.
yintegerThe horizontal column coordinate where input starts.

Returns

TypeDescription
stringThe string entered by the user, or an empty string if cancelled via Escape.

revoke_selection()

@classmethod
def revoke_selection()

Sends a revoke command to the cluster for the currently selected task.


selection_info()

@classmethod
def selection_info()

Displays a detailed view of the selected task's metadata, including arguments and keyword arguments.


selection_traceback()

@classmethod
def selection_traceback()

Displays the error traceback for the selected task if it failed with an exception.


selection_result()

@classmethod
def selection_result()

Displays the return value or exception message of the currently selected task.


display_task_row()

@classmethod
def display_task_row(
lineno: integer,
task: object
)

Renders a single task's information onto a specific line of the curses window with appropriate styling.

Parameters

NameTypeDescription
linenointegerThe row index in the window where the task should be drawn.
taskobjectThe task state object containing UUID, name, worker, and status info.

draw()

@classmethod
def draw()

Refreshes the entire monitor UI, including the task list, selection details, worker status, and help footer.


safe_add_str()

@classmethod
def safe_add_str(
y: integer,
x: integer,
string: string
)

Adds a string to the window while ensuring it does not exceed the screen width to prevent curses errors.

Parameters

NameTypeDescription
yintegerThe row coordinate.
xintegerThe column coordinate.
stringstringThe text to display.

init_screen()

@classmethod
def init_screen()

Initializes the curses environment, sets up colors, and configures input modes.


resetscreen()

@classmethod
def resetscreen()

Restores the terminal to its original state and closes the curses window.


nap()

@classmethod
def nap()

Suspends execution for a short duration defined by the screen delay to control refresh frequency.


tasks()

@classmethod
def tasks() - > list

Retrieves the current list of tasks from the state, limited to what can fit on the screen.

Returns

TypeDescription
listA list of task tuples sorted by time.

workers()

@classmethod
def workers() - > list

Retrieves a list of hostnames for all workers currently marked as alive.

Returns

TypeDescription
listA list of strings representing active worker hostnames.