Skip to content

Commit

Permalink
cache webmention endpoint discovery errors; drop cache expiration to 2h
Browse files Browse the repository at this point in the history
before this, we only cached webmention endpoint discovery results when we successfully fetched the page. this is a bit aggressive, since it means we'll cache transient network failures, but with the lower expiration (2h instead of 1d), and now that the retry button flushes the cache (#524), i think it's ok.

for #534
  • Loading branch information
snarfed committed Oct 31, 2015
1 parent af7ec75 commit f4c00ae
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tasks.py
Expand Up @@ -510,22 +510,21 @@ def do_send_webmentions(self):
if 'DNS lookup failed for URL:' in str(e)
else {'code': 'EXCEPTION'})

if not cached:
memcache.set(cache_key, error if error else mention.receiver_endpoint,
time=WEBMENTION_DISCOVERY_CACHE_TIME)

if error is None:
logging.info('Sent! %s', mention.response)
self.record_source_webmention(mention)
self.entity.sent.append(target)
if not cached:
memcache.set(cache_key, mention.receiver_endpoint,
time=WEBMENTION_DISCOVERY_CACHE_TIME)
else:
code = error['code']
status = error.get('http_status', 0)
if (code == 'NO_ENDPOINT' or
(code == 'BAD_TARGET_URL' and status == 204)): # 204 is No Content
logging.info('Giving up this target. %s', error)
self.entity.skipped.append(target)
if not cached and code == 'NO_ENDPOINT':
memcache.set(cache_key, error, time=WEBMENTION_DISCOVERY_CACHE_TIME)
elif code in ('BAD_TARGET_URL', 'RECEIVER_ERROR') and status / 100 == 4:
# Give up on 4XX errors; we don't expect later retries to succeed.
logging.info('Giving up this target. %s', error)
Expand Down

0 comments on commit f4c00ae

Please sign in to comment.