Puts the module into an errored state where it cannot accept new events. Optionally logs a warning message. The function sets the module's `errored` attribute to True and logs a warning with the optional message. It also clears the incoming event queue to prevent further pr
(self, message=None, clear_outgoing_queue=False, critical=False)
| 1034 | self.debug("Not in an acceptable state to queue outgoing event") |
| 1035 | |
| 1036 | def set_error_state(self, message=None, clear_outgoing_queue=False, critical=False): |
| 1037 | """ |
| 1038 | Puts the module into an errored state where it cannot accept new events. Optionally logs a warning message. |
| 1039 | |
| 1040 | The function sets the module's `errored` attribute to True and logs a warning with the optional message. |
| 1041 | It also clears the incoming event queue to prevent further processing and updates its status to False. |
| 1042 | |
| 1043 | Args: |
| 1044 | message (str, optional): Additional message to be logged along with the warning. |
| 1045 | |
| 1046 | Returns: |
| 1047 | None: The function doesn't return anything but updates the `errored` state and clears the incoming event queue. |
| 1048 | |
| 1049 | Examples: |
| 1050 | >>> self.set_error_state() |
| 1051 | >>> self.set_error_state("Failed to connect to the server") |
| 1052 | |
| 1053 | Notes: |
| 1054 | - The function sets `self._incoming_event_queue` to False to prevent its further use. |
| 1055 | - If the module was already in an errored state, the function will not reset the error state or the queue. |
| 1056 | """ |
| 1057 | if not self.errored: |
| 1058 | log_msg = "Setting error state" |
| 1059 | if message is not None: |
| 1060 | log_msg += f": {message}" |
| 1061 | if critical: |
| 1062 | log_fn = self.error |
| 1063 | else: |
| 1064 | log_fn = self.warning |
| 1065 | log_fn(log_msg) |
| 1066 | self.errored = True |
| 1067 | # clear incoming queue |
| 1068 | if self.incoming_event_queue is not False: |
| 1069 | self.debug("Emptying event_queue") |
| 1070 | with suppress(asyncio.queues.QueueEmpty): |
| 1071 | while 1: |
| 1072 | self.incoming_event_queue.get_nowait() |
| 1073 | # set queue to None to prevent its use |
| 1074 | # if there are leftover objects in the queue, the scan will hang. |
| 1075 | self._incoming_event_queue = False |
| 1076 | |
| 1077 | if clear_outgoing_queue: |
| 1078 | with suppress(asyncio.queues.QueueEmpty): |
| 1079 | while 1: |
| 1080 | self.outgoing_event_queue.get_nowait() |
| 1081 | |
| 1082 | def is_incoming_duplicate(self, event, add=False): |
| 1083 | if event.type in ("FINISHED",): |
no test coverage detected