INNER CODE UNIT · Python
clear_service_tokens
skyportal/skyportal · services/assistant/app.py:433
def clear_service_tokens():
"""Drop the tokens a previous run left behind by dying mid-answer."""
session_context_id.set(uuid.uuid4().hex)
try:
with DBSession() as session:
cleared = session.execute(
sa.delete(Token).where(Token.name.like(f"{SERVICE_TOKEN_PREFIX}%"))
).rowcount
session.commit()
except Exception as exc:
log(f"could not clear the tokens of a previous run: {exc}")
return
finally:
DBSession.remove()
if cleared:
log(f"cleared {cleared} token(s) left by a previous run")