def get_time_permit(self, hash_mpin_id_hex, date_epoch, signature):
"""Get time permit from cache or request new."""
if options.cacheTimePermits:
time_permit_item = self.storage.find(time_permit_id=hash_mpin_id_hex, time_permit_date=date_epoch)
if time_permit_item:
# Get time permit from cache
raise tornado.gen.Return(time_permit_item.time_permit)
# No cached time permits for this mpin id, request new from D-TA
time_permits = yield self.get_time_permits(hash_mpin_id_hex, signature)
if options.cacheTimePermits:
self.cache_time_permits(time_permits, hash_mpin_id_hex)
# Return the one for today
if str(date_epoch) not in time_permits:
log.error("DTA /timePermit Failed. No time permit for today")
raise HTTPError(500)
raise tornado.gen.Return(time_permits[str(date_epoch)])
评论列表
文章目录