Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywink committed Aug 7, 2015
1 parent 6649143 commit 89c6b46
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ build
eggs
parts
bin
var
var/*
!.placeholder
sdist
develop-eggs
.installed.cfg
Expand Down
11 changes: 11 additions & 0 deletions social_relay/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# No need to change this normally, override in locals if needed
import logging
import os

RELAY_USERNAME = "relay"

# Just something hcard needs, override in locals if you want to customize
Expand All @@ -15,6 +18,14 @@

POD_LIST_JSON = "http://the-federation.info/pods.json"

LOG_PATH = "var/social-relay.log"

logging.basicConfig(
filename=os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", LOG_PATH),
level=logging.DEBUG,
format='%(asctime)s:%(levelname)s:%(module)s: %(message)s'
)

from social_relay.local_config import *

# Make sure we have a GUID
Expand Down
3 changes: 2 additions & 1 deletion tasks/fetch_pod_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from redis import Redis
import requests
import schedule
Expand All @@ -9,7 +10,7 @@


def fetch_pod_lists():
print("Fetching pod list")
logging.info("Fetching pod list")
response = requests.get(config.POD_LIST_JSON)
data = response.json()
# TODO: also remove inactives from list
Expand Down
7 changes: 5 additions & 2 deletions tasks/poll_pods.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _socket import timeout
import logging
from redis import Redis
import requests
from requests.exceptions import ConnectionError, Timeout
Expand All @@ -12,7 +13,7 @@

def get_pod_relay_preferences(host):
"""Query remote pods on https first, fall back to http."""
print("Querying %s" % host)
logging.info("Querying %s" % host)
try:
try:
response = requests.get("https://%s/.well-known/x-social-relay" % host, timeout=5)
Expand All @@ -31,14 +32,16 @@ def get_pod_relay_preferences(host):


def poll_pods():
print("Polling pods")
logging.info("Polling pods")
pods = r.hgetall("pods")
for pod, data in pods.items():
data = get_pod_relay_preferences(pod.decode("utf-8"))
if data:
logging.debug("Pod: %s, preferences: %s" % (pod.decode("utf-8"), data))
r.hset("pod_preferences", pod, data)
else:
if r.hexists("pod_preferences", pod):
logging.debug("Pod %s preferences not found, deleting cached data" % pod.decode("utf-8"))
r.hdel("pod_preferences", pod)


Expand Down
Empty file added var/.placeholder
Empty file.
9 changes: 7 additions & 2 deletions workers/receive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from _socket import timeout
import json
import logging
from federation.controllers import handle_receive
from federation.entities.base import Post
from federation.exceptions import NoSuitableProtocolFoundError
Expand Down Expand Up @@ -32,7 +33,7 @@ def send_payload(host, payload):
Return True or False, depending on success of operation.
Timeouts or connection errors will not be raised.
"""
print("Sending payload to %s" % host)
logging.info("Sending payload to %s" % host)
try:
try:
response = requests.post("https://%s/receive/public" % host, data=payload, timeout=10)
Expand All @@ -51,15 +52,19 @@ def process(payload):
"""Open payload and route it to any pods that might be interested in it."""
try:
sender, protocol_name, entities = handle_receive(payload, skip_author_verification=True)
logging.debug("sender=%s, protocol_name=%s, entities=%s" % (sender, protocol_name, entities))
except NoSuitableProtocolFoundError:
logging.warning("No suitable protocol found for payload")
return
if protocol_name != "diaspora":
logging.warning("Unsupported protocol: %s, sender: %s" % (protocol_name, sender))
return
if not entities:
logging.warning("No entities in payload")
return
send_to_pods = pods_who_want_all()
for entity in entities:
print(entity)
logging.info("Entity: %s" % entity)
# We only care about posts atm
if isinstance(entity, Post):
# Send out
Expand Down

0 comments on commit 89c6b46

Please sign in to comment.