本文整理汇总了Python中afqueue.common.exception_formatter.ExceptionFormatter.get_message方法的典型用法代码示例。如果您正苦于以下问题:Python ExceptionFormatter.get_message方法的具体用法?Python ExceptionFormatter.get_message怎么用?Python ExceptionFormatter.get_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类afqueue.common.exception_formatter.ExceptionFormatter
的用法示例。
在下文中一共展示了ExceptionFormatter.get_message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: query_remote_shared_memory
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
def query_remote_shared_memory(self, pqm_id_string, query_method, *arguments):
"""
Directs the shared memory object to query the remote shared memory of the given PQM.
Supply the method to run against the remote shared memory and the arguments required to normally make that call.
Note you will need the full method signature. For example:
If you call with shared_memory_manager.query_remote_shared_memory, supply shared_memory_manager.<method_name>.
Note: If a connection information can't be found, a RedisConnectionUnknownException will be raised. Be sure to check for this and handle as desired!
Note: If a connection can't be made to remote shared memory, a RedisConnectionFailureException will be raised. Be sure to check for this and handle as desired!
"""
# Get the remote client; raise an unknown exception if we have no data mapped for the PQM ID String.
remote_redis_client = self._pqm_redis_client_dict.get(pqm_id_string, None)
if remote_redis_client == None:
raise RedisConnectionUnknownException(pqm_id_string)
# Temporarily overwrite our client and run the command.
qm_redis_client = self._qm_redis_client
self._qm_redis_client = remote_redis_client
# Ensure we don't permanently set our main redis client to the remote redis client by trapping
try:
# Run the query, reset our redis client, and return the result.
result = query_method(*arguments)
self._qm_redis_client = qm_redis_client
return result
except:
# If we hit an exception, reset our redis client, and raise a connection failure exception.
self._qm_redis_client = qm_redis_client
#del(self._pqm_redis_client_dict[pqm_id_string])
raise RedisConnectionFailureException(ExceptionFormatter.get_message())
示例2: create_from_received
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
def create_from_received(raw_message):
"""
Returns a new message of this type from the raw message data.
"""
try:
return ClientRequeueDataReplyMessage(None, raw_message[1], raw_message[2])
except:
raise ReplyTranslationException(ExceptionFormatter.get_message())
示例3: _log_exception
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
def _log_exception(self, as_incident = True, note = "", increment_statsd = True):
# Log the exception.
self.logger.log_error("::: *** EXCEPTION: {0}".format(ExceptionFormatter.get_message()), as_incident)
if note != "":
self.logger.log_error("::: *** EXCEPTION - Note: {0}".format(note))
# Send to the exception bucket.
if increment_statsd == True:
Utility.send_stats_count(self.statsd_library, self.config.STATSD_NETWORK_BRIDGE_EXCEPTION_COUNT, 1)
示例4: consume_action_queue
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
def consume_action_queue(thread_name, action_queue, notification_out_queue):
# Enter a loop which will only break when we receive no more messages from the queue we are handling.
while True:
try:
# Get a new message; initialize it to not handled.
message = action_queue.get(False)
message_handled = False
if message.get_primary_type() == message_types.SYSTEM:
if message.get_type() == message_types.SYSTEM_STOP_THREAD:
notification_out_queue.put(system_messages.SystemNotificationMessage(thread_name, "Shutting down per main thread request"))
message_handled = True
return False
# If the message hasn't been handled, notify.
if message_handled == False:
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Thread notification handler found a message it could not process: " + str(message)))
except EmptyQueueException:
# Break from the loop; there are no more messages to handle.
break
except IOError as e:
# Notify of the IO error and return True (which will signal a shut down).
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "IO Error ({0}). Shutting down.".format(e)))
return False
except:
# Notify the general exception.
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Exception while checking in-bound notifications: " + ExceptionFormatter.get_message()))
return False
# Return true - we should keep running.
return True
示例5: peer_request_thread
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
#.........这里部分代码省略.........
# This will allow us to see if we should shut down the socket in between polls.
# This will also allow us to check our request queue to add more connections to the poller.
poller = zmq.Poller()
# We will need to track our current dealer sockets and which peer queue manager they map to.
peer_id_string_to_request_socket_map = dict()
# Define a socket connection method.
def _connect_socket(peer_queue_manager_id_string, connection_string):
# If there is a socket for the peer given already in the map, disconnect.
if peer_queue_manager_id_string in list(peer_id_string_to_request_socket_map.keys()):
_disconnect_socket(peer_queue_manager_id_string)
# Connect.
request_socket = zmq_context.socket(zmq.REQ)
request_socket.connect(connection_string)
peer_id_string_to_request_socket_map[peer_queue_manager_id_string] = request_socket
poller.register(request_socket, zmq.POLLIN)
# Send a system message to notify we have closed the socket.
notification_queue.put(system_messages.SystemSocketStateMessage(thread_name, True, "Request: {0}".format(peer_queue_manager_id_string)))
# Define a socket disconnection method.
def _disconnect_socket(peer_queue_manager_id_string):
# If there is a socket for the peer given in the map, disconnect.
if peer_queue_manager_id_string in list(peer_id_string_to_request_socket_map.keys()):
# Disconnect
request_socket = peer_id_string_to_request_socket_map[peer_queue_manager_id_string]
request_socket.setsockopt(zmq.LINGER, 0)
request_socket.close()
poller.unregister(request_socket)
# Remove from our tracker.
del(peer_id_string_to_request_socket_map[peer_queue_manager_id_string])
# Send a system message to notify we have closed the socket.
notification_queue.put(system_messages.SystemSocketStateMessage(thread_name, False, "Request: {0}".format(peer_queue_manager_id_string)))
# Send a system message to notify we have started our thread.thread.
notification_queue.put(system_messages.SystemThreadStateMessage(thread_name, True, os.getpid()))
# Enter a loop in which we wait for a router request message.
is_running = True
while is_running == True:
try:
# Get a new message; initialize to not being handled.
# Note that we will be routed to our empty message exception if no messages are waiting.
message = action_queue.get(True, 1)
message_handled = False
# Branch off message type.
if message.get_type() == message_types.SYSTEM_CONNECT_PEER_REQUEST_SOCKET:
# Connect.
_connect_socket(message.peer_queue_manager_id_string, message.connection_string)
# Denote message as handled.
message_handled = True
elif message.get_type() == message_types.SYSTEM_DISCONNECT_PEER_REQUEST_SOCKET:
# Disconnect.
_disconnect_socket(message.peer_queue_manager_id_string)
# Denote message as handled.
message_handled = True
elif message.get_type() == message_types.SYSTEM_STOP_THREAD:
notification_queue.put(system_messages.SystemNotificationMessage(thread_name, "Shutting down per main thread request"))
message_handled = True
is_running = False
# If the message hasn't been handled, notify.
if message_handled == False:
notification_queue.put(system_messages.SystemErrorMessage(thread_name, "Action queue message was not handled: {0}".format(message)))
except EmptyQueueException:
pass
except:
# When we get an exception, log it and break from our loop.
notification_queue.put(system_messages.SystemErrorMessage(thread_name, "Action queue message processing raised exception: " + ExceptionFormatter.get_message()))
break
# Close all sockets.
peer_id_string_list = list(peer_id_string_to_request_socket_map.keys())
for peer_id_string in peer_id_string_list:
_disconnect_socket(peer_id_string)
# Send a system message to notify we have shut down.
notification_queue.put(system_messages.SystemThreadStateMessage(thread_name, False))
示例6: __init__
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
def __init__(self, statsd_library, client_router_port, config, logger):
try:
# Assign.
self.config = config
self.logger = logger
self.statsd_library = statsd_library
# Denote running and not shut down.
self.is_running = True
self.shut_down_ran = False
# Create the thread process ID tracker.
self._thread_process_id_dict = dict()
# Set up our socket information.
self._data_client_request_socket_port = client_router_port
self._command_request_socket_port = client_router_port + 1
self._bridge_worker_router_socket_port = client_router_port + 2
# Create the thread notification queue.
# Most threads in the system will use this queue to put all data which the main thread needs to access.
self._child_thread_notification_queue = Queue()
self._load_balancer_thread_action_queue = Queue()
self._command_request_action_queue = Queue()
# When a bridge worker times out, the bridge will automatically try to recreate a new socket connection.
# The tracker and time stamp dictionaries are used to track which connections to recreate and when we are allowed to create them.
# The interval at which we check if we should recreate, how many we can create in a period, and the period itself are all configuration values.
self._worker_recreation_tracker_dict = dict()
self._worker_recreation_time_stamp_dict = dict()
self._last_worker_recreation_check_time = 0
self.config.bridge_worker_recreation_max_per_period = 10
self.config.bridge_worker_recreation_period = 90
# Create the ZMQ context.
self._zmq_context = zmq.Context(1)
# Create the command thread; utilized to receive commands from external sources.
self._bridge_command_thread_process = Process(target=bridge_command_request_thread,
args=(self.config.bridge_command_request_thread_name,
self._zmq_context, None, # We have no shared memory object in the bridge at this point.
self._command_request_socket_port, self.config.zmq_poll_timeout,
self._command_request_action_queue, self._child_thread_notification_queue,),
name=self.config.bridge_command_request_thread_name)
# Create the data broker thread (read thread method's description for processing information).
self._bridge_broker_process = Process(target=bridge_load_balancer_thread,
args=(self.config.bridge_load_balancer_thread_name,
self._zmq_context, self.config.bridge_poll_timeout,
self._data_client_request_socket_port, self._bridge_worker_router_socket_port,
self._load_balancer_thread_action_queue, self._child_thread_notification_queue,),
name=self.config.bridge_load_balancer_thread_name)
# Start our process threads.
self._bridge_command_thread_process.start()
self._bridge_broker_process.start()
# Create the bridge worker manager.
self._bridge_worker_manager = BridgeWorkerManager(self.config, self._zmq_context, self._bridge_worker_router_socket_port, self._child_thread_notification_queue, self.logger)
# We should give our threads some time to start up and then handle all notifications from them before proceeding.
time.sleep(0.5)
if self._handle_notifications() == False:
raise Exception("Initial notification handling failed")
# Make initial connections found in the configuration file.
for connection_type, remote_connection_information, connection_count in self.config.bridge_data_worker_connections:
# Form a connection message, like we would receive from the commander script, from the parameters.
if connection_type == "zmq":
remote_ip, remote_port = remote_connection_information.split(":")
message = command_messages.CommandRemoteConnectRequestMessage(remote_ip, remote_port, connection_count)
elif connection_type == "pika":
message = command_messages.CommandRemoteConnectPikaRequestMessage(remote_connection_information, self.config.bridge_data_worker_pika_connection_type,
connection_count)
else:
raise Exception("Unknown connection type specified in initial bridge data worker connections in config file.")
# Put in our notification queue.
self._child_thread_notification_queue.put(message, False)
except:
# Ensure we call shut down to destroy any sockets we may have created.
try:
self.shut_down()
except:
pass
# Raise out.
raise Exception("Initialization failed: " + ExceptionFormatter.get_message())
示例7: bridge_command_request_thread
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
#.........这里部分代码省略.........
action_out_queue.put(decoded_message)
reply_message = command_messages.CommandReplyMessage(command_response_codes.COMMAND_RECEIVED)
# If the decoding failed, notify the main thread and set the reply accordingly.
else:
action_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Malformed message received."))
reply_message = command_messages.CommandReplyMessage(command_response_codes.MALFORMED_MESSAGE)
elif raw_message_type == message_types.COMMAND_REMOTE_CONNECT_REQUEST:
# Decode.
decoded_message = command_messages.CommandRemoteConnectRequestMessage.create_from_received(raw_message)
# If the decoding was successful, handle the message.
if decoded_message != None:
action_out_queue.put(decoded_message)
reply_message = command_messages.CommandReplyMessage(command_response_codes.COMMAND_RECEIVED)
# If the decoding failed, notify the main thread and set the reply accordingly.
else:
action_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Malformed message received."))
reply_message = command_messages.CommandReplyMessage(command_response_codes.MALFORMED_MESSAGE)
elif raw_message_type == message_types.COMMAND_REMOTE_DISCONNECT_REQUEST:
# Decode.
decoded_message = command_messages.CommandRemoteDisconnectRequestMessage.create_from_received(raw_message)
# If the decoding was successful, handle the message.
if decoded_message != None:
action_out_queue.put(decoded_message)
reply_message = command_messages.CommandReplyMessage(command_response_codes.COMMAND_RECEIVED)
# If the decoding failed, notify the main thread and set the reply accordingly.
else:
action_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Malformed message received."))
reply_message = command_messages.CommandReplyMessage(command_response_codes.MALFORMED_MESSAGE)
elif raw_message_type == message_types.COMMAND_REMOTE_CONNECT_PIKA_REQUEST:
# Decode.
decoded_message = command_messages.CommandRemoteConnectPikaRequestMessage.create_from_received(raw_message)
# If the decoding was successful, handle the message.
if decoded_message != None:
action_out_queue.put(decoded_message)
reply_message = command_messages.CommandReplyMessage(command_response_codes.COMMAND_RECEIVED)
# If the decoding failed, notify the main thread and set the reply accordingly.
else:
action_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Malformed message received."))
reply_message = command_messages.CommandReplyMessage(command_response_codes.MALFORMED_MESSAGE)
elif raw_message_type == message_types.COMMAND_REMOTE_DISCONNECT_PIKA_REQUEST:
# Decode.
decoded_message = command_messages.CommandRemoteDisconnectPikaRequestMessage.create_from_received(raw_message)
# If the decoding was successful, handle the message.
if decoded_message != None:
action_out_queue.put(decoded_message)
reply_message = command_messages.CommandReplyMessage(command_response_codes.COMMAND_RECEIVED)
# If the decoding failed, notify the main thread and set the reply accordingly.
else:
action_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Malformed message received."))
reply_message = command_messages.CommandReplyMessage(command_response_codes.MALFORMED_MESSAGE)
# Handle unknown.
else:
reply_message = command_messages.CommandReplyMessage(command_response_codes.COMMAND_UNKNOWN)
# Send a response.
reply_message.send(request_socket)
except KeyboardInterrupt:
# Ignore keyboard interrupts; the main thread will handle as desired.
pass
except:
# When we get an exception, log it and break from our loop.
action_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Failed to receive an incoming message: " + ExceptionFormatter.get_message()))
break
# Consume our action queue; the result is if we should continue running.
if consume_action_queue(thread_name, action_queue, action_out_queue) == False:
break
# Clean up the bridge socket.
request_socket.setsockopt(zmq.LINGER, 0)
request_socket.close()
poller.unregister(request_socket)
action_out_queue.put(system_messages.SystemSocketStateMessage(thread_name, False, "Request"))
# Send a system message to notify we have shut down.
action_out_queue.put(system_messages.SystemThreadStateMessage(thread_name, False))
示例8: run
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
def run(self):
# Log entry and register signal.
logger.log_info("Process started: {0}".format(self.parsed_arguments))
# Setup StatsD.
if config.STATSD_ENABLED == True:
from afqueue.stats.client import Statsd
from afqueue.stats.afclient import AFTransport
Statsd.set_transport(AFTransport(logger=logger.get_logger()))
else:
Statsd = None
# Setup the signal handler.
global SIGNAL_RECEIVED
signal.signal(signal.SIGUSR1, sighandler)
signal.signal(signal.SIGUSR2, sighandler)
# Get the remote IP we will tell other machines to use to connect to us.
remote_ip = self.parsed_arguments.remote_ip
if remote_ip == None:
remote_ip_interface = self.parsed_arguments.remote_ip_interface
if remote_ip_interface == None:
config.remote_ip_interface
remote_ip = NetworkUtilities.get_interface_ip_address(remote_ip_interface)
logger.log_info("Found and used IP {0} as remote IP.".format(remote_ip))
# Create the queue manager.
queue_manager = QueueManager(remote_ip, self.parsed_arguments.port,
self.parsed_arguments.peer, config, logger, Statsd, self.parsed_arguments.redis_address)
try:
# Update the process name before going into our loop.
self.update_process_name()
# Enter the queue read and process loop.
while queue_manager.is_running:
# Run the bridge loop.
if queue_manager.run_loop() == False:
logger.log_error("Error running main loop. Shutting down.")
# Check if we've received a signal.
if SIGNAL_RECEIVED != None:
# USR1: Shut down.
if SIGNAL_RECEIVED == signal.SIGUSR1:
break
# USR1: Reload config.
elif SIGNAL_RECEIVED == signal.SIGUSR2:
logger.log_info("::: RELOAD CONFIG ENCOUNTERED ::: Not coded yet")
# Reset signal.
SIGNAL_RECEIVED = None
# Sleep.
time.sleep(0.1)
except KeyboardInterrupt:
# Log.
logger.log_info("Shutdown keyboard command received. Shutting down ...")
except:
# Log the exception.
logger.log_error("::: *** EXCEPTION: {0}".format(ExceptionFormatter.get_message()), True)
finally:
# Force shut down if it hasn't been ran.
if queue_manager.shut_down_ran == False:
queue_manager.shut_down()
# Log entry and register signal.
logger.log_info("Process stopped")
示例9: pqm_incoming_message_thread
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
def pqm_incoming_message_thread(thread_name, dealer_id_string, poll_timeout, no_activity_sleep,
action_queue, notification_queue, received_message_queue):
"""
This thread is responsible for handling incoming messages from PQMs.
An outside thread can command this thread to take action via the action queue.
Results and notifications are put in the notification queue (when necessary).
A PQM connection action will create a dealer socket to the desired PQM.
This thread will then watch for incoming messages from that PQM.
Messages received from PQMs will be put on the PQM received message queue.
Note that this ROUTER/DEALER connection relationship is modeled after PUSH/PULL for asynchronous data transmission.
"""
# Send a system message to notify we have started our thread.thread.
notification_queue.put(system_messages.SystemThreadStateMessage(thread_name, True, os.getpid()))
# We will need to track our current dealer sockets and which peer queue manager they map to.
dealer_socket_to_id_string_map = dict()
# Create our ZMQ context.
zmq_context = zmq.Context(1)
# Use a poller so we can receive with timeouts (receive is blocking; we can poll with a timeout).
# This will allow us to see if we should shut down the socket in between polls.
# This will also allow us to check our request queue to add more connections to the poller.
poller = zmq.Poller()
# Enter our loop.
# We have two steps:
# 1) Accept any data sent to our dealer sockets by PQMs (poll to check for existence).
# 2) Respond to requests put this thread's action queue.
is_running = True
while is_running == True:
# Track if we have handled any data in each iteration so we know if we should sleep or not to give the CPU some rest.
handled_data = False
# 1) Accept any data sent to our dealer sockets by PQMs.
try:
# Poll for socket events.
socket_events_dictionary = dict(poller.poll(poll_timeout))
# Check each dealer socket in our map.
for dealer_socket in list(dealer_socket_to_id_string_map.keys()):
# If the dealer socket has data waiting, process it.
if dealer_socket in socket_events_dictionary and socket_events_dictionary[dealer_socket] == zmq.POLLIN:
# Receive.
received_message = SocketWrapper.pull_message(dealer_socket)
# Place the PQM's id string and received message in our received queue.
# Received messages are handled outside of this thread; we must allow it to continue receiving uninterrupted.
received_message_queue.put((dealer_socket_to_id_string_map[dealer_socket], received_message))
# Denote data was handled.
handled_data = True
except KeyboardInterrupt:
# Ignore keyboard interrupts; the main thread will handle as desired.
pass
except:
# When we get an exception, log it and break from our loop.
notification_queue.put(system_messages.SystemErrorMessage(thread_name, "Failed to receive an incoming PQM message: " + ExceptionFormatter.get_message()))
break
# 2) Respond to requests put this thread's action queue.
action_queue_exception = False
while True:
try:
# Get a new message; initialize to not being handled.
# Note that we will be routed to our empty message exception if no messages are waiting.
message = action_queue.get(False)
message_handled = False
# Denote data was handled.
handled_data = True
# Based on the message type, handle.
if message.get_type() == message_types.SYSTEM_PEER_CONNECTION_UDPATE:
# If we should connect.
if message.connect_flag == True:
# This message is requesting we make a DEALER socket connection to the given peer.
# Create the dealer socket, setting the identity to this QM.
# This will tell tell the corresponding ROUTER running on the PQM to only send data intended for this QM.
dealer_socket = zmq_context.socket(zmq.DEALER)
dealer_socket.setsockopt(zmq.IDENTITY, message.dealer_id_string.encode())
dealer_socket.connect(message.peer_socket_connection_string)
# Send a system message to notify we have opened our socket.
notification_queue.put(system_messages.SystemSocketStateMessage(thread_name, True, "Dealer connected to {0} in response to action request.".format(message.peer_socket_connection_string)))
#.........这里部分代码省略.........
示例10: bridge_pika_worker_thread
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
#.........这里部分代码省略.........
try:
data = bson.loads(request_message.data_tuple_dumped)[request_message.routing_key]
except:
# If we fail with bson, try again using json + decode.
import json
data = json.loads(request_message.data_tuple_dumped)[1].decode("base64")
"""
# Forward the message to the remote socket, tracking traversal time.
response = client_response_codes.PIKA_DATA_PUSH_SUCCESS
start_time = time.time()
try:
# Publish.
pika_publisher.publish(request_message.exchange_name, routing_key, data, logger)
# Check time.
current_time = time.time()
time_to_send = current_time - start_time
if time_to_send > 1:
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Time taken to send message is too long: {0}".format(time_to_send)))
response = client_response_codes.PIKA_DATA_PUSH_SUCCESS_LONG_SEND
except:
try:
# Publish.
pika_publisher.publish(request_message.exchange_name, routing_key, data, logger)
# Update response code.
response = client_response_codes.PIKA_DATA_PUSH_SUCCESS_AFTER_RETRY
# Check time.
current_time = time.time()
time_to_send = current_time - start_time
except:
# Notify.
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "Failed in both primary and secondary send attempts; exception: " + ExceptionFormatter.get_message()))
# Update response code.
response = client_response_codes.PIKA_DATA_PUSH_FAILED_TWICE
# Check time.
current_time = time.time()
time_to_send = current_time - start_time
# Create the reply and send it.
reply_message = client_messages.ClientDataPushReplyMessage(reply_id_tag, response, "")
reply_message.send(bridge_request_socket)
# Increment statistics.
call_count += 1
total_call_send_time += time_to_send
dt = datetime.datetime.fromtimestamp(current_time)
if dt.minute != last_minute_sent:
last_minute_sent = dt.minute
notification_out_queue.put(system_messages.SystemStatsMessage(thread_name, "call_count", call_count))
notification_out_queue.put(system_messages.SystemStatsMessage(thread_name, "art", (total_call_send_time / call_count) * 1000))
call_count = 0
total_call_send_time = 0
except KeyboardInterrupt:
# Ignore keyboard interrupts; the main thread will handle as desired.
pass
except zmq.ZMQError:
# When we get an exception, log it and break from our loop.
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "ZMQ error raised while processing request: " + ExceptionFormatter.get_message()))
break
except:
# When we get an exception, log it and break from our loop.
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "General exception raised while processing request: " + ExceptionFormatter.get_message()))
break
# Consume our action queue; the result is if we should continue running.
if consume_action_queue(thread_name, action_queue, notification_out_queue) == False:
break
# Clean up the bridge socket.
bridge_request_socket.setsockopt(zmq.LINGER, 0)
bridge_request_socket.close()
bridge_poller.unregister(bridge_request_socket)
notification_out_queue.put(system_messages.SystemSocketStateMessage(thread_name, False, "Bridge request"))
# Clean up the remote socket.
pika_publisher.close()
notification_out_queue.put(system_messages.SystemSocketStateMessage(thread_name, False, "Remote request"))
# Send a system message to notify we have shut down.
notification_out_queue.put(system_messages.SystemThreadStateMessage(thread_name, False))
示例11: DaemonWrapper
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
self.current_process_name = current_process_name
self.set_proc_name(self.current_process_name)
if __name__ == "__main__":
# Create the daemon wrapper.
daemon = DaemonWrapper(parsed_arguments)
try:
# Start in debug or daemon mode based on the optional debug flag.
if parsed_arguments.debug == "on":
print("Executing start debug command; Stdout being displayed.")
daemon.start_debug()
else:
print("Executing start daemon command...")
daemon.start()
except SystemExit:
pass
except Exception:
logger.log_error(ExceptionFormatter.get_message())
raise ExceptionFormatter.get_full_exception()
sys.exit(0)
示例12: bridge_worker_thread
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
#.........这里部分代码省略.........
last_time_sent = time.time()
notification_interval = 30
except:
raise ExceptionFormatter.get_full_exception()
polling = True;
while polling == True:
try:
# Poll on receiving with our time out.
if bridge_poller.poll(load_balancer_time_out):
# Get the message; initialize to not handled.
full_raw_message = SocketWrapper.pull_message(bridge_request_socket)
# Pull the reply tag and raw message data out of the full raw message.
reply_id_tag = full_raw_message[0]
raw_message = full_raw_message[2:]
# Forward the message to the remote socket.
for data in raw_message[:-1]:
ZmqUtilities.send_data(remote_request_socket, data, zmq.SNDMORE)
ZmqUtilities.send_data(remote_request_socket, raw_message[-1])
# Wait for a response from the remote socket.
if remote_poller.poll(remote_poll_timeout):
# Capture the response.
response_message = SocketWrapper.pull_message(remote_request_socket)
# Put the reply tag on the message and send the received response back to the bridge.
ZmqUtilities.send_data(bridge_request_socket, reply_id_tag, zmq.SNDMORE)
bridge_request_socket.send(b"", zmq.SNDMORE)
for data in response_message[:-1]:
ZmqUtilities.send_data(bridge_request_socket, data, zmq.SNDMORE)
ZmqUtilities.send_data(bridge_request_socket, response_message[-1])
# Increment statistics.
current_time = time.time()
call_count += 1
if current_time - last_time_sent > notification_interval:
last_time_sent = current_time
notification_out_queue.put(system_messages.SystemNotificationMessage(thread_name, "Handled {0} calls in the past {1} seconds.".format(call_count, notification_interval)))
call_count = 0
# If we timed out waiting for a response from the remote socket.
else:
# Send a TIMEOUT string to the bridge request socket.
ZmqUtilities.send_data(bridge_request_socket, reply_id_tag, zmq.SNDMORE)
bridge_request_socket.send(b"", zmq.SNDMORE)
bridge_request_socket.send(b"TIMEOUT")
# Report a time out.
# This will ultimately lead the main thread to stop tracking this thread.
notification_out_queue.put(system_messages.SystemBridgeWorkerTimedOut(thread_name, "Timed out waiting for response from remote socket."))
# Stop polling.
polling = False
except KeyboardInterrupt:
# Ignore keyboard interrupts; the main thread will handle as desired.
pass
except zmq.ZMQError:
# When we get an exception, log it and break from our loop.
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "ZMQ error raised while processing request: " + ExceptionFormatter.get_message()))
break
except:
# When we get an exception, log it and break from our loop.
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "General exception raised while processing request: " + ExceptionFormatter.get_message()))
break
# Consume our action queue; the result is if we should continue running.
if consume_action_queue(thread_name, action_queue, notification_out_queue) == False:
break
# Clean up the bridge socket.
bridge_request_socket.setsockopt(zmq.LINGER, 0)
bridge_request_socket.close()
bridge_poller.unregister(bridge_request_socket)
notification_out_queue.put(system_messages.SystemSocketStateMessage(thread_name, False, "Bridge request"))
# Clean up the remote socket.
remote_request_socket.setsockopt(zmq.LINGER, 0)
remote_request_socket.close()
remote_poller.unregister(remote_request_socket)
notification_out_queue.put(system_messages.SystemSocketStateMessage(thread_name, False, "Remote request"))
# Send a system message to notify we have shut down.
notification_out_queue.put(system_messages.SystemThreadStateMessage(thread_name, False))
示例13: bridge_load_balancer_thread
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
#.........这里部分代码省略.........
sleep_flag = False
# Get the full raw message and break it into separate components.
full_raw_message = SocketWrapper.pull_message(client_router_socket)
client_id_tag = full_raw_message[0]
raw_message = full_raw_message[2:]
# Pop off the oldest worker marked as available.
worker_id_tag = available_worker_id_tag_list.pop(0)
# Forward the request to the worker.
ZmqUtilities.send_data(worker_router_socket, worker_id_tag, zmq.SNDMORE)
worker_router_socket.send(b"", zmq.SNDMORE)
ZmqUtilities.send_data(worker_router_socket, client_id_tag, zmq.SNDMORE)
worker_router_socket.send(b"", zmq.SNDMORE)
for data in raw_message[:-1]:
ZmqUtilities.send_data(worker_router_socket, data, zmq.SNDMORE)
ZmqUtilities.send_data(worker_router_socket, raw_message[-1])
# Check the sleep flag for this iteration.
if sleep_flag == True:
# We sleep when no traffic came in or out of the broker.
time.sleep(0.1)
except KeyboardInterrupt:
# Ignore keyboard interrupts; the main thread will handle as desired.
pass
except zmq.ZMQError:
# When we get an exception, log it and break from our loop.
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "ZMQ error raised while processing request: " + ExceptionFormatter.get_message()))
break
except:
# When we get an exception, log it and break from our loop.
notification_out_queue.put(system_messages.SystemErrorMessage(thread_name, "General exception raised while processing request: " + ExceptionFormatter.get_message()))
break
# Respond to requests put this thread's action queue.
action_queue_exception = False
while True:
try:
# Get a new message; initialize to not being handled.
# Note that we will be routed to our empty message exception if no messages are waiting.
message = action_queue.get(False)
message_handled = False
# Based on the message type, handle.
if message.get_type() == message_types.SYSTEM_STOP_THREAD:
notification_out_queue.put(system_messages.SystemNotificationMessage(thread_name, "Shutting down per main thread request"))
message_handled = True
is_running = False
elif message.get_type() == message_types.SYSTEM_THREAD_STATE:
if message.started_flag == False:
if message.thread_name in available_worker_id_tag_list:
available_worker_id_tag_list.remove(message.thread_name)
notification_out_queue.put(system_messages.SystemNotificationMessage(thread_name, "Worker thread stopped notification from main thread resulted in worker removal from active list: {0}".format(message.thread_name)))
else:
notification_out_queue.put(system_messages.SystemNotificationMessage(thread_name, "Worker thread stopped notification from main thread resulted in worker removal: {0}".format(message.thread_name)))
示例14: pqm_outgoing_message_thread
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
#.........这里部分代码省略.........
except:
# Do not allow to run.
notification_queue.put(system_messages.SystemErrorMessage(thread_name, "*****************************"))
is_running = False
# Enter a loop in which we wait for a router request message.
while is_running == True:
try:
# Get a new message; initialize to not being handled.
# Note that we will be routed to our empty message exception if no messages are waiting.
message = action_queue.get(True)
message_handled = False
# We should only receive a send data request.
if message.get_primary_type() == message_types.PEER:
# Heart beat related messages: Send the message as is.
if message.get_type() == message_types.PEER_HEART_BEAT or message.get_type() == message_types.PEER_HEART_BEAT_FAILURE:
# Forward and denote as handled.
message.send(router_socket)
message_handled = True
if message.get_type() == message_types.PEER_ORDERED_QUEUES_OWNERS_EXHAUSTED or message.get_type() == message_types.PEER_FORWARDED_COMMAND_MESSAGE:
# Forward and denote as handled.
message.send(router_socket)
message_handled = True
elif message.get_type() == message_types.PEER_MASTER_SETUP_DATA or message.get_type() == message_types.PEER_MASTER_CONTROL_DATA:
# Forward and denote as handled.
message.send(router_socket)
message_handled = True
elif message.get_type() == message_types.PEER_CLIENT_DECLARE_EXCHANGES_REQUEST or message.get_type() == message_types.PEER_CLIENT_DECLARE_QUEUES_REQUEST:
# Forward and denote as handled.
message.send(router_socket)
message_handled = True
elif message.get_type() == message_types.PEER_CLIENT_DELETE_QUEUES_REQUEST or message.get_type() == message_types.PEER_REQUEST_MASTER_DATA:
# Forward and denote as handled.
message.send(router_socket)
message_handled = True
elif message.get_type() == message_types.PEER_CLIENT_LOCK_QUEUES_REQUEST or message.get_type() == message_types.PEER_CLIENT_UNLOCK_QUEUES_REQUEST:
# Forward and denote as handled.
message.send(router_socket)
message_handled = True
elif message.get_type() == message_types.PEER_OFFLINE:
# Forward and denote as handled.
message.send(router_socket)
message_handled = True
# Check for a system shut down.
elif message.get_primary_type() == message_types.SYSTEM:
if message.get_type() == message_types.SYSTEM_STOP_THREAD:
notification_queue.put(system_messages.SystemNotificationMessage(thread_name, "Shutting down per main thread request"))
message_handled = True
is_running = False
# If the message hasn't been handled, notify.
if message_handled == False:
notification_queue.put(system_messages.SystemErrorMessage(thread_name, "Action queue message was not handled: {0}".format(message)))
except EmptyQueueException:
pass
except KeyboardInterrupt:
# Ignore keyboard interrupts; the main thread will handle as desired.
pass
except:
# When we get an exception, log it and break from our loop.
notification_queue.put(system_messages.SystemErrorMessage(thread_name, "Action queue message processing raised exception: " + ExceptionFormatter.get_message()))
break
# Clean up the socket.
if router_socket != None:
router_socket.setsockopt(zmq.LINGER, 0)
router_socket.close()
# Send a system message to notify we have closed the socket.
notification_queue.put(system_messages.SystemSocketStateMessage(thread_name, False, "Router"))
# Send a system message to notify we have shut down.
notification_queue.put(system_messages.SystemThreadStateMessage(thread_name, False))
示例15: _run_logic
# 需要导入模块: from afqueue.common.exception_formatter import ExceptionFormatter [as 别名]
# 或者: from afqueue.common.exception_formatter.ExceptionFormatter import get_message [as 别名]
#.........这里部分代码省略.........
idle_worker_id_tag_time_dict[worker_id_tag] = time.time()
# Strip off the directive.
directive = full_raw_message[2]
# If the directive is READY, we have nothing more to do: the worker was added to our available worker list already.
# If the directive is the client reply address, forward to the client.
if directive != b"READY":
# Get the raw message from the full raw message.
raw_message = full_raw_message[4:]
# Forward, with the directive (which is the client reply id tag).
final_raw_message = [directive, b""] + raw_message
client_router_socket.send_multipart(final_raw_message)
# XXX
available_worker_id_tag_list.append(worker_id_tag)
# Only poll for incoming requests if there are workers available to take the them.
if len(available_worker_id_tag_list) > 0:
if socket_events_dictionary.get(client_router_socket) == zmq.POLLIN:
# Set no sleep.
sleep_flag = False
# Get the full raw message and break it into separate components.
full_raw_message = client_router_socket.recv_multipart()
client_id_tag = full_raw_message[0]
raw_message = full_raw_message[2:]
# If there's raw data.
if len(raw_message) > 0:
# Pop off the oldest worker marked as available.
worker_id_tag = available_worker_id_tag_list.pop(0)
# Capture the oldest worker was added, compare it to our current time, and track.
current_time = time.time()
added_time = idle_worker_id_tag_time_dict.get(worker_id_tag, current_time)
handled_count += 1
idle_time += current_time - added_time
# Forward the request to the worker.
final_raw_message = [worker_id_tag, b"", client_id_tag, b""] + raw_message
worker_router_socket.send_multipart(final_raw_message)
# If there's no raw data.
else:
# Notify.
self.action_out_queue.put(system_messages.SystemErrorMessage(self.thread_name, "Incoming message has no fields. Sending empty message to sender."))
# Send a reply back to the sender with no data.
client_router_socket.send_multipart(client_id_tag, b"", b"")
# Check the sleep flag for this iteration.
if sleep_flag == True:
# We sleep when no traffic came in or out of the broker.
time.sleep(0.1)
except KeyboardInterrupt:
# Ignore keyboard interrupts; the main thread will handle as desired.
pass
except zmq.ZMQError:
# When we get an exception, log it and break from our loop.
self.action_out_queue.put(system_messages.SystemErrorMessage(self.thread_name, "ZMQ error raised while processing request: " + ExceptionFormatter.get_message()))
break
except:
# When we get an exception, log it and break from our loop.
self.action_out_queue.put(system_messages.SystemErrorMessage(self.thread_name, "General exception raised while processing request: " + ExceptionFormatter.get_message()))
break
# Check our action queue.
self._consume_action_queue(available_worker_id_tag_list)
# Clean up the sockets.
if client_router_socket != None:
client_router_socket.setsockopt(zmq.LINGER, 0)
client_router_socket.close()
if worker_router_socket != None:
worker_router_socket.setsockopt(zmq.LINGER, 0)
worker_router_socket.close()
if poller != None:
poller.unregister(client_router_socket)
poller.unregister(worker_router_socket)
# Send a system message to notify we have closed the socket.
self.action_out_queue.put(system_messages.SystemSocketStateMessage(self.thread_name, False, "Router"))
self.action_out_queue.put(system_messages.SystemSocketStateMessage(self.thread_name, False, "Dealer"))
# Send a system message to notify we have shut down.
self.action_out_queue.put(system_messages.SystemThreadStateMessage(self.thread_name, False))