Skip to main content

th2_act

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

th2_act-1.0.0.dev2435496660.tar.gz (13.0 kB view details)

Uploaded Source

File details

Details for the file th2_act-1.0.0.dev2435496660.tar.gz.

File metadata

  • Download URL: th2_act-1.0.0.dev2435496660.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for th2_act-1.0.0.dev2435496660.tar.gz
Algorithm Hash digest
SHA256 cf22e624dff3c168fb508fec1f1f6f2824981ecf9c727e89e210b6de0664ba70
MD5 f1633014022c3626273432ebeec6b558
BLAKE2b-256 229f06e77077ae8c357a54acd2e5bda3c92101feb472c1634e5895b531f41af5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page