chg: Catch aiohttp.ClientError

pull/12/head
Raphaël Vinot 2018-04-04 23:34:48 +02:00
parent 76ec7ff379
commit 9904404003
1 changed files with 12 additions and 9 deletions

View File

@ -133,15 +133,18 @@ class Fetcher():
if not await self.__newer(): if not await self.__newer():
unset_running('{}-{}-{}'.format(self.__class__.__name__, self.vendor, self.listname)) unset_running('{}-{}-{}'.format(self.__class__.__name__, self.vendor, self.listname))
return return
async with aiohttp.ClientSession() as session: try:
async with session.get(self.url) as r: async with aiohttp.ClientSession() as session:
content = await r.content.read() async with session.get(self.url) as r:
if self.__same_as_last(content): content = await r.content.read()
return if self.__same_as_last(content):
self.logger.info('Got a new file \o/') return
with (self.directory / '{}.txt'.format(datetime.now().isoformat())).open('wb') as f: self.logger.info('Got a new file \o/')
f.write(content) with (self.directory / '{}.txt'.format(datetime.now().isoformat())).open('wb') as f:
unset_running('{}-{}-{}'.format(self.__class__.__name__, self.vendor, self.listname)) f.write(content)
unset_running('{}-{}-{}'.format(self.__class__.__name__, self.vendor, self.listname))
except aiohttp.ClientError as e:
self.logger.exception('Fetching the list failed: {}'.format(e))
except PidFileError: except PidFileError:
self.logger.info('Fetcher already running') self.logger.info('Fetcher already running')
finally: finally: