def handle_db_request(self, queue):
"""
Handle incoming requests from :class:`DbClient` instances.
"""
address, empty, msg = queue.recv_multipart()
msg, *args = pickle.loads(msg)
try:
handler = {
'ALLPKGS': self.do_allpkgs,
'ALLVERS': self.do_allvers,
'NEWPKG': self.do_newpkg,
'NEWVER': self.do_newver,
'LOGBUILD': self.do_logbuild,
'PKGFILES': self.do_pkgfiles,
'PKGEXISTS': self.do_pkgexists,
'GETABIS': self.do_getabis,
'GETPYPI': self.do_getpypi,
'SETPYPI': self.do_setpypi,
'GETSTATS': self.do_getstats,
}[msg]
result = handler(*args)
except Exception as exc:
self.logger.error('Error handling db request: %s', msg)
# REP *must* send a reply even when stuff goes wrong
# otherwise the send/recv cycle that REQ/REP depends
# upon breaks
queue.send_multipart([address, empty,
pickle.dumps(['ERR', str(exc)])])
else:
queue.send_multipart([address, empty,
pickle.dumps(['OK', result])])
评论列表
文章目录