Skip to content

Commit

Permalink
updated mismatch log
Browse files Browse the repository at this point in the history
  • Loading branch information
neyer committed Nov 9, 2012
1 parent eb19866 commit 241bbf2
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import logging
import json_tools
from webob import Request
from gevent.pywsgi import WSGIHandler, WSGIServer

class Handler(object):
Expand All @@ -15,21 +16,22 @@ def __init__(self,master,apprentices):

self._mismatch_log = logging.getLogger("darkside-mismatch")
self._mismatch_log.setLevel(logging.INFO)
self._mismatch_log.addHandler(logging.FileHandler('darkside-mismatch.log'))
file_handler = logging.FileHandler('darkside-mismatch.log')
file_handler.setFormatter(logging.Formatter('%(asctime)s\n----\n%(message)s'))
self._mismatch_log.addHandler(file_handler)

def __call__(self,environ,start_response):

path = environ['PATH_INFO']
query_string = environ['QUERY_STRING']
method = environ['REQUEST_METHOD']

incoming = Request(environ)

all_bodies = []
all_servers = [ self._master] + self._apprentices
master_response = None
master_body = None

for server in all_servers:
req = self.make_request(environ, server)
req = self.make_request(incoming, server)
req.send()
this_body = req.response.content
try:
Expand All @@ -42,7 +44,8 @@ def __call__(self,environ,start_response):
master_body = this_response

if not this_response == master_body:
self._mismatch_log.info('apprentice %s failed fetching %s?%s' % (server, path,query_string))
self._mismatch_log.info('apprentice %s failed fetching %s?%s:\n----\n%s\n---vs---\n%s' %
(server, incoming.path,incoming.query_string, this_response, master_body))
if isinstance(this_response, dict) and isinstance(master_body, dict):
diff = json_tools.diff(this_response,master_body)
all_bodies.append(this_response)
Expand All @@ -55,10 +58,10 @@ def __call__(self,environ,start_response):
start_response('200 OK',[])
return 'fudgesickles'

def make_request(self, environ, for_server):
return requests.Request(url=for_server+environ['PATH_INFO'],
method=environ['REQUEST_METHOD'],
params=environ['QUERY_STRING'])
def make_request(self, incoming_request, for_server):
return requests.Request(url=for_server+incoming_request.path,
method=incoming_request.method,
params=dict(incoming_request.GET.items()))

def main():
#set up the arguments parser
Expand Down

0 comments on commit 241bbf2

Please sign in to comment.