Best Python code snippet using localstack_python
clients.py
Source:clients.py
...18 typing.Mapping19 """20 raise NotImplementedError21 @abc.abstractmethod22 def change_message_visibility(self, message, timeout):23 """24 Update the message visibility.25 Parameters26 ----------27 message : downloadbot.common.messaging.messages.Message28 timeout : int29 Returns30 -------31 typing.Mapping32 """33 raise NotImplementedError34class SqsFifo(Client):35 def __init__(self, sqs_queue):36 """37 Parameters38 ----------39 sqs_queue : boto3.resources.factory.sqs.Queue40 """41 self._sqs_queue = sqs_queue42 def delete_message(self, message):43 request = {44 'Entries': [45 {46 'Id': message.id,47 'ReceiptHandle': message.delivery_receipt48 }49 ]50 }51 # See this warning.52 # http://boto3.readthedocs.io/en/latest/reference/services/sqs.html#SQS.Queue.delete_messages53 response = self._sqs_queue.delete_messages(**request)54 return response55 def change_message_visibility(self, message, timeout):56 request = {57 'Entries': [58 {59 'Id': message.id,60 'ReceiptHandle': message.delivery_receipt,61 'VisibilityTimeout': timeout62 }63 ]64 }65 response = self._sqs_queue.change_message_visibility_batch(**request)66 return response67 def __repr__(self):68 repr_ = '{}(sqs_queue={})'69 return repr_.format(self.__class__.__name__, self._sqs_queue)70class Orchestrating(Client):71 def __init__(self, client, retry_policy, logger):72 """73 Component to include error handling and logging.74 Parameters75 ----------76 client : downloadbot.infrastructure.queuing.clients.Client77 retry_policy : downloadbot.common.retry.policy.Policy78 logger : logging.Logger79 """80 self._client = client81 self._retry_policy = retry_policy82 self._logger = logger83 def delete_message(self, message):84 response = dict()85 delete = functools.partial(self._client.delete_message,86 message=message)87 try:88 response = self._retry_policy.execute(delete)89 except retry.exceptions.MaximumRetry as e:90 # An expected case has persisted.91 self._logger.critical(msg=utility.format_exception(e=e))92 return response93 def change_message_visibility(self, message, timeout):94 response = self._client.change_message_visibility(message,95 timeout=timeout)96 return response97 def __repr__(self):98 repr_ = '{}(client={}, retry_policy={}, logger={})'99 return repr_.format(self.__class__.__name__,100 self._client,101 self._retry_policy,...
reader.py
Source:reader.py
...25 raise ExitError("No more messages to replay")26 return dict(Messages=messages)27 def delete_message(self, *args, **kwargs):28 pass29 def change_message_visibility(self, *args, **kwargs):30 pass31class SQSStdInReader:32 """33 Read message data from stdin.34 """35 def receive_message(self, MaxNumberOfMessages, **kwargs):36 limit = MaxNumberOfMessages37 messages = []38 for _ in range(limit):39 message = stdin.readline()40 if message == "":41 break42 messages.append(loads(message))43 if not messages:44 raise ExitError("No more messages to replay")45 return dict(Messages=messages)46 def delete_message(self, *args, **kwargs):47 pass48 def change_message_visibility(self, *args, **kwargs):49 pass50class SQSJsonReader:51 """52 Read message data from a JSON string.53 Accepts single message, but appended to list for backward compatibility54 """55 def __init__(self, message):56 self.message = message57 def receive_message(self, **kwargs):58 return dict(Messages=[self.message])59 def delete_message(self, *args, **kwargs):60 pass61 def change_message_visibility(self, *args, **kwargs):...
robot_error_handler.py
Source:robot_error_handler.py
...9 try:10 instance = worker()11 instance(record)12 except Exception:13 self.sqs_error_handler.change_message_visibility(record)14class SQSErrorHandler:15 def __init__(self):16 self.sqs_client = boto3.client('sqs')17 def change_message_visibility(self, record):18 if settings.is_local:19 return20 self.sqs_client.change_message_visibility(21 QueueUrl=self.sqs_url(record),22 ReceiptHandle=record['receiptHandle'],23 VisibilityTimeout=30024 )25 self.sqs_client.send_message(26 MessageBody=record['body'],27 QueueUrl=self.sqs_url(record),28 DelaySeconds=3029 )30 def sqs_url(self, record):31 sqs_name = record['eventSourceARN']32 worker_id = re.search(33 r'^arn:aws:sqs:us-east-(1|2):(\d+):worker_(?P<worker_id>.*?)$',34 sqs_name...
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!!