Best Python code snippet using autotest_python
de84bc1c0d9d2e25633452bdefc2dcf233d2b27edispatch.py
Source:de84bc1c0d9d2e25633452bdefc2dcf233d2b27edispatch.py  
1#!/usr/bin/env python2"""3Example JSON data for dispatch process.4-- request from client --5{6    "request_type" : "add_monitor_entry", # or "update_monitor_entry", "delete_monitor_entry"7    "netid" : "xxxxxxxx",8    "crn" : "xxxxx",9    "mode" : "x"10}11"""12import socket13import json14import multiprocessing15import logging16import database17from monitor import Monitor18class Dispatch(object):19    20    _TIMEOUT = 60021    22    def __init__(self, conn, address):23        self.conn = conn24        self.address = address25        self.db = database.DatabaseCommunicator()26        # self.conn.settimeout(_TIMEOUT)27        self.logger = logging.getLogger('Dispatch')28        logging.basicConfig(level=logging.DEBUG)29        30        self.logger.debug('dispatch launched')31    32    def _monitorLauncher(self, crn):33        monitor = Monitor(crn)34    35    def listen(self):36        try:37            while True:38                # try:39                dispatchRequest = self.conn.recv(2048)40                # except socket.timeout:41                #    self.logger.debug('Timeout!')42                #    break43                if dispatchRequest == '':44                    self.logger.debug('Socket closed from client')45                    return46                if dispatchRequest == '\n':47                    continue48                self.logger.info('Dispatch request received.')49                self.logger.debug(dispatchRequest)50                51                dispatchRequestJSON = json.loads(dispatchRequest)52                requestType = dispatchRequestJSON['request_type']53                netid = dispatchRequestJSON['netid']54                crn = dispatchRequestJSON['crn']55                mode = dispatchRequestJSON['mode']56                57                if requestType == 'add_monitor_entry':58                    notificationInterval = dispatchRequestJSON['notification_interval']59                    self.logger.debug('parse interval = ' + str(notificationInterval))60                    self.db.addMonitorEntry(netid, crn, mode, notificationInterval)61                    self.logger.debug('add entry')62                    if self.db.newMonitorRequired(crn):63                        # new monitor process64                        process = multiprocessing.Process(target=self._monitorLauncher, args=(crn))65                        process.daemon = True66                        process.start()67                    dispatchResponse = dict(request_type='add_monitor_entry', request_status='Accepted')68                if requestType == 'update_monitor_entry':69                    notificationInterval = dispatchRequestJSON['notification_interval']70                    lastNotification = dispatchRequestJSON['last_notification']71                    self.db.updateMonitorEntry(netid, crn, mode, notificationInterval, lastNotification)72                    dispatchResponse = dict(request_type='update_monitor_entry', request_status='Accepted')73                if requestType == 'delete_monitor_entry':74                    self.db.deleteMonitorEntry(netid, crn)75                    dispatchResponse = dict(request_type='delete_monitor_entry', request_status='Accepted')76                self.conn.sendall(json.dumps(dispatchResponse) + '\n')77                continue78        except:79            self.logger.debug('Unknown error')80        finally:81            self.logger.debug('Closing current socket')...FrontControllerPattern.py
Source:FrontControllerPattern.py  
...25        print("User is authenticated successfully.")26        return True27    def trackRequest(self, request: str):28        print("Page requested: {}".format(request))29    def dispatchRequest(self, request: str):30        self.trackRequest(request)31        if self.isAuthenticUser():32            self.dispatcher.dispatch(request)33# ä½¿ç¨ FrontController æ¥æ¼ç¤ºå端æ§å¶å¨è®¾è®¡æ¨¡å¼ã34if __name__ == '__main__':35    frontController = FrontController()36    frontController.dispatchRequest("HOME")...DispatchAck.py
Source:DispatchAck.py  
1# This is a generated file, do not edit2from typing import List3import pydantic4from ..rmf_task_msgs.DispatchRequest import DispatchRequest5class DispatchAck(pydantic.BaseModel):6    dispatch_request: DispatchRequest = (7        DispatchRequest()8    )  # rmf_task_msgs/DispatchRequest9    success: bool = False  # bool10    class Config:11        orm_mode = True12        schema_extra = {13            "required": [14                "dispatch_request",15                "success",16            ],17        }18# # This message is published by the fleet adapter in response to a19# # DispatchRequest message. It indicates whether the requested task addition or20# # cancellation was successful.21#22# # The DispatchRequest message received by the Fleet Adapter23# DispatchRequest dispatch_request24#25# # True if the addition or cancellation operation was successful...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
