Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

TH2 Act Component (Python)

Overview

This repository is a library for custom gRPC act projects (check th2-act-template-py for the implementation template). The th2-act contains helper methods to create custom ActHadlers that implements custom gRPC API. Multiple ActHandlers allowed as well.

Act is a passive th2 component with parameterized functions which is implemented as part of the test logic. Script or other components can call these functions via gRPC. Act can interact with conn (Connects), hands, check1s, other acts to execute its tasks. Information about the progress of the task is published to the estore th2 component via MQ pin. This th2 component type allows frequently used script logic into it and then share it between all th2 components.

Most of them consists of the next steps:

  1. Gets a gRPC request with parameters.
  2. Requests checkpoint from check1 via gRPC pin
  3. Sends the passed business message to Connect via mq pin
  4. Waits the specific business message from Connect during specified timeout
  5. Returns responded business message with checkpoint

picture

Installation

To install th2-act package run the following command in the terminal:

pip install th2-act

Usage

Classes Act and GRPCServer may be used in act implementation to upload act-handlers and run gRPC server.

RequestProcessor context manager may be used in act implementation to send requests to conn, save all received messages to the cache and retrieve messages from there using the filters described by the user.

RequestProcessor has several methods to work with its cache:

  • method that returns first message that matches one of the filters:
    receive_first_matching(message_filters: Dict[Callable, int],
                           timeout: Union[int, float] = None,
                           check_previous_messages: bool = True) -> ActResponse
    
  • method that returns first N messages that match the filters:
    receive_first_n_matching(message_filters: Dict[Callable, int],
                             n: int,
                             timeout: Union[int, float] = None,
                             check_previous_messages: bool = True) -> List[ActResponse]
    
  • method that returns all messages preceding the first message (including it) that matches one of the filters:
    receive_all_before_matching(message_filters: Dict[Callable, int],
                                timeout: Union[int, float] = None,
                                check_previous_messages: bool = True) -> List[ActResponse]
    
  • method that returns all messages following the first message (including it) that matches one of the filters:
    receive_all_after_matching(message_filters: Dict[Callable, int],
                               wait_time: Union[int, float] = None,
                               check_previous_messages: bool = True) -> List[ActResponse]
    
  • method that returns all messages that match the filters:
    receive_all_matching(message_filters: Dict[Callable, int],
                         wait_time: Union[int, float] = None,
                         check_previous_messages: bool = True) -> List[ActResponse]
    

Methods have the following arguments:

Name Status Type Defaults Meaning
message_filters required Dict[lambda, RequestStatus.status] - The filter (lambda or function) through which the messages from cache will be filtered out - as key, RequestStatus (SUCCESS or ERROR) - as value.
n required int - How much messages to return.
timeout optional int of float context time remaining The time (in seconds) during which you are ready to wait for the messages. The messages will be returned as soon as the first matching message is found.
wait_time optional int of float None The time (in seconds) that the Act will wait before checking the cache for the matching message. Defaults to None (cache will be checked immediately and only once).
check_previous_messages optional bool True Set True if you want to look for the response throughout all received responses; set False if you want to check only newly received responses.

All methods return either a ActResponse class instance or a list of ActResponse class instances. ActResponse class contains the following fields:

  • message - Message
  • status - RequestStatus
  • checkpoint - CheckpointID
  • text - str

Schematically, the interaction with the RequestProcessor class can be represented as follows:

picture

Implementation template is here.

Metadata

Release files for th2-act 1.0.0.dev2433181901

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for th2-act 1.0.0.dev2433181901
File Size Uploaded
th2_act-1.0.0.dev2433181901.tar.gz 12.9 kB Details

Release files / th2_act-1.0.0.dev2433181901.tar.gz

Download URL th2_act-1.0.0.dev2433181901.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cab83c75d46079f6616018a8ebb0e6a92f35e658886feec6782df9ed8b01bead
BLAKE2b-256 checksum
How to use checksums
511781c50ca7f7b56ec223a2b9c85114c6ead33270fbbfef39aa9e0facc89c6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page