コード例 #1
0
ファイル: test_workers.py プロジェクト: dmorley/social-relay
 def test_send_payload_stores_unknown_node_into_db(self, mock_handle_receive, mock_send_payload,
                                                   mock_pod_preferences):
     process(Mock())
     assert Node.select().count() == 1
     node = Node.get(Node.host=="sub.example.com")
     assert node
     assert node.https
コード例 #2
0
 def test_get_send_to_nodes_with_like_returns_nodes_for_post(self):
     Node.create(host="sub.example.com")
     save_post_metadata(DiasporaPost(guid="12345"), "diaspora",
                        ["sub.example.com"])
     nodes = get_send_to_nodes("*****@*****.**",
                               DiasporaLike(target_guid="12345"))
     assert nodes == ["sub.example.com"]
コード例 #3
0
ファイル: test_workers.py プロジェクト: jaywink/social-relay
 def test_send_payload_success_clears_existing_node_failure_count(
     self, mock_handle_receive, mock_send_document, mock_pod_preferences
 ):
     Node.create(host="sub.example.com", last_success=datetime.datetime.now(), failure_count=1)
     process(Mock())
     node = Node.get(Node.host == "sub.example.com")
     assert node.failure_count == 0
コード例 #4
0
ファイル: statistics.py プロジェクト: dmorley/social-relay
def get_count_stats():
    day_ago = datetime.datetime.now() - datetime.timedelta(hours=24)
    week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
    month_ago = datetime.datetime.now() - datetime.timedelta(days=30)
    incoming = {
        "today": ReceiveStatistic.select().where(ReceiveStatistic.created_at >= day_ago).count(),
        "week": ReceiveStatistic.select().where(ReceiveStatistic.created_at >= week_ago).count(),
        "month": ReceiveStatistic.select().where(ReceiveStatistic.created_at >= month_ago).count(),
        "all_time": ReceiveStatistic.select().count(),
    }
    outgoing = {
        "today": WorkerReceiveStatistic.select().where(WorkerReceiveStatistic.created_at >= day_ago).count(),
        "week": WorkerReceiveStatistic.select().where(WorkerReceiveStatistic.created_at >= week_ago).count(),
        "month": WorkerReceiveStatistic.select().where(WorkerReceiveStatistic.created_at >= month_ago).count(),
        "all_time": WorkerReceiveStatistic.select().count(),
    }
    distinct_nodes = {
        "all": Node.select().count(),
        "https": Node.select().where(Node.https==True).count(),
    }
    processing = {
        "workers": get_worker_count(),
        "queue_jobs": len(public_queue),
    }
    return incoming, outgoing, distinct_nodes, processing
コード例 #5
0
ファイル: test_workers.py プロジェクト: jaywink/social-relay
 def test_send_payload_updates_existing_node_in_db(
     self, mock_handle_receive, mock_send_document, mock_pod_preferences
 ):
     Node.create(host="sub.example.com", last_success=datetime.datetime.now())
     process(Mock())
     node = Node.get(Node.host == "sub.example.com")
     assert node.total_delivered == 1
     assert node.https
コード例 #6
0
ファイル: test_workers.py プロジェクト: jaywink/social-relay
 def test_send_payload_failure_updates_existing_node_failure_count(
     self, mock_handle_receive, mock_send_payload, mock_pod_preferences
 ):
     Node.create(host="sub.example.com", last_success=datetime.datetime.now())
     mock_send_payload.return_value = {"result": False, "https": False}
     process(Mock())
     node = Node.get(Node.host == "sub.example.com")
     assert node.failure_count == 1
コード例 #7
0
 def test_send_payload_success_clears_existing_node_failure_count(
         self, mock_handle_receive, mock_send_document,
         mock_pod_preferences):
     Node.create(host="sub.example.com",
                 last_success=datetime.datetime.now(),
                 failure_count=1)
     process(Mock())
     node = Node.get(Node.host == "sub.example.com")
     assert node.failure_count == 0
コード例 #8
0
 def test_send_payload_stores_unknown_node_into_db(self,
                                                   mock_handle_receive,
                                                   mock_send_document,
                                                   mock_pod_preferences):
     process(Mock())
     assert Node.select().count() == 1
     node = Node.get(Node.host == "sub.example.com")
     assert node
     assert node.https
コード例 #9
0
 def test_send_payload_failure_updates_existing_node_failure_count(
         self, mock_handle_receive, mock_send_payload,
         mock_pod_preferences):
     Node.create(host="sub.example.com",
                 last_success=datetime.datetime.now())
     mock_send_payload.return_value = {"result": False, "https": False}
     process(Mock())
     node = Node.get(Node.host == "sub.example.com")
     assert node.failure_count == 1
コード例 #10
0
 def test_send_payload_updates_existing_node_in_db(self,
                                                   mock_handle_receive,
                                                   mock_send_document,
                                                   mock_pod_preferences):
     Node.create(host="sub.example.com",
                 last_success=datetime.datetime.now())
     process(Mock())
     node = Node.get(Node.host == "sub.example.com")
     assert node.total_delivered == 1
     assert node.https
コード例 #11
0
ファイル: statistics.py プロジェクト: royalterra/social-relay
def get_count_stats():
    day_ago = datetime.datetime.now() - datetime.timedelta(hours=24)
    week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
    month_ago = datetime.datetime.now() - datetime.timedelta(days=30)
    incoming = {
        "today":
        ReceiveStatistic.select().where(
            ReceiveStatistic.created_at >= day_ago).count(),
        "week":
        ReceiveStatistic.select().where(
            ReceiveStatistic.created_at >= week_ago).count(),
        "month":
        ReceiveStatistic.select().where(
            ReceiveStatistic.created_at >= month_ago).count(),
        "all_time":
        ReceiveStatistic.select().count(),
    }
    outgoing = {
        "today":
        WorkerReceiveStatistic.select().where(
            WorkerReceiveStatistic.created_at >= day_ago).count(),
        "week":
        WorkerReceiveStatistic.select().where(
            WorkerReceiveStatistic.created_at >= week_ago).count(),
        "month":
        WorkerReceiveStatistic.select().where(
            WorkerReceiveStatistic.created_at >= month_ago).count(),
        "all_time":
        WorkerReceiveStatistic.select().count(),
    }
    distinct_nodes = {
        "all": Node.select().count(),
        "https": Node.select().where(Node.https == True).count(),
    }
    processing = {
        "workers": get_worker_count(),
        "queue_jobs": len(public_queue),
    }
    return incoming, outgoing, distinct_nodes, processing
コード例 #12
0
def save_post_metadata(entity, protocol, hosts):
    """Save Post metadata to db.

    :param entity: DiasporaPost entity
    :param protocol: Protocol identifier
    :param hosts: List of hostnames that send was done successfully
    """
    try:
        post, created = Post.get_or_create(guid=entity.guid, protocol=protocol)
        for host in hosts:
            post.nodes.add(Node.get(host=host))
    except Exception as ex:
        logging.warning("Exception when trying to save post '{entity}' into database: {exc}".format(
            entity=entity, exc=ex))
コード例 #13
0
ファイル: receive.py プロジェクト: dmorley/social-relay
def save_post_metadata(entity, protocol, hosts):
    """Save Post metadata to db.

    :param entity: DiasporaPost entity
    :param protocol: Protocol identifier
    :param hosts: List of hostnames that send was done successfully
    """
    try:
        post, created = Post.get_or_create(guid=entity.guid, protocol=protocol)
        for host in hosts:
            post.nodes.add(Node.get(host=host))
    except Exception as ex:
        logging.warning("Exception when trying to save post '{entity}' into database: {exc}".format(
            entity=entity, exc=ex))
コード例 #14
0
ファイル: receive.py プロジェクト: dmorley/social-relay
def update_node(pod, response):
    """Update Node in database

    :param pod: Hostname
    :param response: Dictionary with booleans "result" and "https"
    """
    try:
        Node.get_or_create(host=pod)
        if response["result"]:
            # Update delivered_count and last_success, nullify failure_count
            Node.update(
                last_success=datetime.datetime.now(), total_delivered=Node.total_delivered + 1,
                failure_count=0, https=response["https"]).where(Node.host==pod).execute()
        else:
            # Update failure_count
            Node.update(
                failure_count=Node.failure_count + 1).where(Node.host==pod).execute()
    except Exception as ex:
        logging.warning("Exception when trying to save or update Node {node} into database: {exc}".format(
            node=pod, exc=ex)
        )
コード例 #15
0
ファイル: receive.py プロジェクト: bmanojlovic/social-relay
def update_node(pod, response):
    """Update Node in database

    :param pod: Hostname
    :param response: Dictionary with booleans "result" and "https"
    """
    try:
        Node.get_or_create(host=pod)
        if response["result"]:
            # Update delivered_count and last_success, nullify failure_count
            Node.update(
                last_success=datetime.datetime.now(), total_delivered=Node.total_delivered + 1,
                failure_count=0, https=response["https"]).where(Node.host==pod).execute()
        else:
            # Update failure_count
            Node.update(
                failure_count=Node.failure_count + 1).where(Node.host==pod).execute()
    except Exception as ex:
        logging.warning("Exception when trying to save or update Node {node} into database: {exc}".format(
            node=pod, exc=ex)
        )
コード例 #16
0
def update_node(node, success):
    """Update Node in database

    :param node: Hostname
    :param success: Was the last call a success (bool)
    """
    try:
        Node.get_or_create(host=node)
        if success:
            # Update delivered_count and last_success, nullify failure_count
            # TODO: remove the whole https tracking - we're only delivering to https now
            Node.update(
                last_success=datetime.datetime.now(), total_delivered=Node.total_delivered + 1,
                failure_count=0, https=True).where(Node.host == node).execute()
        else:
            # Update failure_count
            Node.update(
                failure_count=Node.failure_count + 1).where(Node.host == node).execute()
    except Exception as ex:
        logging.warning("Exception when trying to save or update Node {node} into database: {exc}".format(
            node=node, exc=ex)
        )
コード例 #17
0
ファイル: test_workers.py プロジェクト: jaywink/social-relay
 def test_get_send_to_nodes_with_like_returns_no_nodes_for_unknown_post(self):
     Node.create(host="sub.example.com")
     save_post_metadata(DiasporaPost(guid="12345"), "diaspora", ["sub.example.com"])
     nodes = get_send_to_nodes("*****@*****.**", DiasporaLike(target_guid="54321"))
     assert nodes == []