RESTAPITracker#

top.restapi.tracker.RESTAPITracker class.

class RESTAPITracker[source]#

Bases: Tracker

REST API integration for getting active HTTP requests from a web server.

Get active and completed requests from the web server direclty.

  • You have a web server that itself can track its active requests and completed responses

  • The web server implements Top Framework REST API for fetching the tasks

  • Used with Node.js integration

__init__(api_url, task_type, api_key=None)[source]#

Create a new emitter.

Parameters:
  • api_url (str) –

    Tracked endpoint at the web server.

    Usually /tracker.

  • api_key (Optional[str]) –

    The API key needed to access the tracker endpoint.

    If not set read from TOP_WEB_API_KEY environment variable.

  • task_type (Type[Task]) – A custom serialisation/deserialisation class for the data.

Methods

__init__(api_url, task_type[, api_key])

Create a new emitter.

clear()

Clear the tracker from old/dangling tasks.

end_task(task)

Finish exisiting task.

get_active_tasks()

Get currently active tasks.

get_completed_tasks()

Get the backlog of completed tasks.

start_task(task)

Start a new task.

__init__(api_url, task_type, api_key=None)[source]#

Create a new emitter.

Parameters:
  • api_url (str) –

    Tracked endpoint at the web server.

    Usually /tracker.

  • api_key (Optional[str]) –

    The API key needed to access the tracker endpoint.

    If not set read from TOP_WEB_API_KEY environment variable.

  • task_type (Type[Task]) – A custom serialisation/deserialisation class for the data.

clear()[source]#

Clear the tracker from old/dangling tasks.

For example if the server has

  • Crashed

  • Restarted

Get rid of any stale data.

Can be called on the web server start.

start_task(task)[source]#

Start a new task.

Record a task started in the tracker backend.

Parameters:

task (Task) –

end_task(task)[source]#

Finish exisiting task.

Mark task completed.

Parameters:

task (Task) –

get_active_tasks()[source]#

Get currently active tasks.

Returns:

Map of (Processor id -> Task)

Return type:

Dict[Union[int, str], Task]

get_completed_tasks()[source]#

Get the backlog of completed tasks.

Each backend can have N number of tasks in a ring buffer that are last completed.

Tasks are in the completion order. The most recently completed task is the first item in the list.

Returns:

List of past completed tasks that are in our past tasks buffer. The most recently completed task is the first item in the list.

Return type:

List[Task]