Browse files

retry on 503 errors

  • Loading branch information...
1 parent 9d6e56f commit 4fc62f58b7c666a458597791a09ec00c611d9030 Dylan Jay committed Jan 25, 2010
Showing with 61 additions and 54 deletions.
  1. +31 −30 pretaweb/funnelweb/remoteconstructor.py
  2. +30 −24 pretaweb/funnelweb/remoteschemaupdater.py
View
61 pretaweb/funnelweb/remoteconstructor.py
@@ -48,35 +48,36 @@ def __iter__(self):
elems = path.strip('/').rsplit('/', 1)
- url = urllib.basejoin(self.target, path)
- proxy = xmlrpclib.ServerProxy(url)
- container, id = (len(elems) == 1 and ('', elems[0]) or elems)
- #if id == 'index.html':
- try:
- #test paths in case of acquition
- rpath = proxy.getPhysicalPath()
- rpath = rpath[len(basepath):]
- if path == '/'.join(rpath):
- yield item
- continue
- except xmlrpclib.Fault:
- pass
- url = urllib.basejoin(self.target,container)
- proxy = xmlrpclib.ServerProxy(url)
- try:
- proxy.invokeFactory(type_, id)
- except xmlrpclib.ProtocolError,e:
- if e.errcode == 302:
- pass
- else:
- raise
- #input = urllib.urlencode({'type_name':type_,
- # 'id':id
- # }
- # )
- #f = urllib.urlopen("%s/invokeFactory" % url, input)
- #nurl = f.geturl()
- #info = f.info()
- #res = f.read()
+ for attempt in range(0, 3):
+ try:
+
+ url = urllib.basejoin(self.target, path)
+ proxy = xmlrpclib.ServerProxy(url)
+ container, id = (len(elems) == 1 and ('', elems[0]) or elems)
+ #if id == 'index.html':
+ try:
+ #test paths in case of acquition
+ rpath = proxy.getPhysicalPath()
+ rpath = rpath[len(basepath):]
+ if path == '/'.join(rpath):
+ break
+ except xmlrpclib.Fault:
+ pass
+ purl = urllib.basejoin(self.target,container)
+ pproxy = xmlrpclib.ServerProxy(purl)
+ try:
+ pproxy.invokeFactory(type_, id)
+ except xmlrpclib.ProtocolError,e:
+ if e.errcode == 302:
+ pass
+ else:
+ raise
+ break
+ except xmlrpclib.ProtocolError,e:
+ if e.errcode == 503:
+ continue
+ else:
+ raise
+ yield item
View
54 pretaweb/funnelweb/remoteschemaupdater.py
@@ -44,24 +44,23 @@ def __iter__(self):
url = urllib.basejoin(self.target, path)
- if True:
- changed = False
- errors = []
-
- # support field arguments via 'fieldname.argument' syntax
- # result is dict with tuple (value, fieldarguments)
- # stored in fields variable
- fields = {}
- for key, value in item.iteritems():
- if key.startswith('_'):
- continue
- parts = key.split('.',1)
- fields.setdefault(parts[0], [None,{}])
- if len(parts)==1:
- fields[parts[0]][0] = value
- else:
- fields[parts[0]][1][parts[1]] = value
-
+ changed = False
+ errors = []
+
+ # support field arguments via 'fieldname.argument' syntax
+ # result is dict with tuple (value, fieldarguments)
+ # stored in fields variable
+ fields = {}
+ for key, value in item.iteritems():
+ if key.startswith('_'):
+ continue
+ parts = key.split('.',1)
+ fields.setdefault(parts[0], [None,{}])
+ if len(parts)==1:
+ fields[parts[0]][0] = value
+ else:
+ fields[parts[0]][1][parts[1]] = value
+
proxy = xmlrpclib.ServerProxy(url)
multicall = xmlrpclib.MultiCall(proxy)
for key, parts in fields.items():
@@ -75,12 +74,19 @@ def __iter__(self):
f = urllib.urlopen(url+'/set%s'%key.capitalize(), input)
nurl = f.geturl()
info = f.info()
- if '_defaultpage' in item:
- proxy.setDefaultPage(item['_defaultpage'])
- #result = multicall()
- proxy.update() #does indexing
- if errors:
- item['_safeatschemaupdater:error'] = errors
+
+ for attempt in range(0,3):
+ try:
+ if '_defaultpage' in item:
+ proxy.setDefaultPage(item['_defaultpage'])
+ #result = multicall()
+ proxy.update() #does indexing
+ break
+ except xmlrpclib.ProtocolError,e:
+ if e.errcode == 503:
+ continue
+ else:
+ raise
yield item

0 comments on commit 4fc62f5

Please sign in to comment.