Esempio n. 1
0
    def _add_queue_depths(self, session, item):

        current_depth_gd_q = session.query(PubSubEndpointEnqueuedMessage.id).\
            filter(PubSubEndpointEnqueuedMessage.cluster_id==self.request.input.cluster_id).\
            filter(PubSubEndpointEnqueuedMessage.sub_key==item.sub_key).\
            filter(PubSubEndpointEnqueuedMessage.is_in_staging != True).\
            filter(PubSubEndpointEnqueuedMessage.delivery_status != COMMON_PUBSUB.DELIVERY_STATUS.DELIVERED)

        # This could be read from the SQL database ..
        item.current_depth_gd = count(session, current_depth_gd_q)

        # .. but non-GD depth needs to be collected from all the servers around. Note that the server may not be known
        # in case the subscriber is a WSX client. In this case, by definition, there will be no non-GD messages for that client.
        sk_server = self.pubsub.get_delivery_server_by_sub_key(item.sub_key)

        if sk_server:

            if sk_server.server_name == self.server.name and sk_server.server_pid == self.server.pid:
                pubsub_tool = self.pubsub.get_pubsub_tool_by_sub_key(item.sub_key)
                _, current_depth_non_gd = pubsub_tool.get_queue_depth(item.sub_key)
            else:
                response = self.servers[sk_server.server_name].invoke(GetEndpointQueueNonGDDepth.get_name(), {
                    'sub_key': item.sub_key,
                }, pid=sk_server.server_pid)
                inner_response = response['response']
                current_depth_non_gd = inner_response['current_depth_non_gd'] if inner_response else 0

        # No delivery server = there cannot be any non-GD messages waiting for that subscriber
        else:
            current_depth_non_gd = 0

        item.current_depth_non_gd = current_depth_non_gd
Esempio n. 2
0
def get_gd_depth_topic(session, cluster_id, topic_id):
    """ Returns current depth of input topic by its ID.
    """
    q = session.query(MsgTable.c.id).\
        filter(MsgTable.c.topic_id==topic_id).\
        filter(MsgTable.c.cluster_id==cluster_id).\
        filter(~MsgTable.c.is_in_sub_queue)

    return count(session, q)
Esempio n. 3
0
def get_queue_depth_by_sub_key(session, cluster_id, sub_key, now):
    """ Returns queue depth for a given sub_key - does not include messages expired, in staging, or already delivered.
    """
    current_q = session.query(PubSubEnqMsg.id).\
        filter(PubSubSubscription.sub_key==PubSubEnqMsg.sub_key).\
        filter(PubSubEnqMsg.is_in_staging != True).\
        filter(PubSubEnqMsg.pub_msg_id==PubSubMessage.pub_msg_id).\
        filter(PubSubMessage.expiration_time>=now).\
        filter(PubSubSubscription.sub_key==sub_key).\
        filter(PubSubEnqMsg.cluster_id==cluster_id) # noqa: E712

    return count(session, current_q)
Esempio n. 4
0
    def _add_queue_depths(self, session, item):

        total_q = session.query(PubSubEndpointEnqueuedMessage.id).\
            filter(PubSubEndpointEnqueuedMessage.cluster_id==self.request.input.cluster_id).\
            filter(PubSubEndpointEnqueuedMessage.sub_key==item.sub_key)

        current_q = session.query(PubSubEndpointEnqueuedMessage.id).\
            filter(PubSubEndpointEnqueuedMessage.cluster_id==self.request.input.cluster_id).\
            filter(PubSubEndpointEnqueuedMessage.sub_key==item.sub_key).\
            filter(PubSubEndpointEnqueuedMessage.is_in_staging != True)

        staging_q = session.query(PubSubEndpointEnqueuedMessage.id).\
            filter(PubSubEndpointEnqueuedMessage.cluster_id==self.request.input.cluster_id).\
            filter(PubSubEndpointEnqueuedMessage.sub_key==item.sub_key).\
            filter(PubSubEndpointEnqueuedMessage.is_in_staging == True)

        total_depth = count(session, total_q)
        current_depth = count(session, current_q)
        staging_depth = count(session, staging_q)

        item.total_depth = total_depth
        item.current_depth = current_depth
        item.staging_depth = staging_depth