Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add datetime and number of requests logging to permalink database.

This will help when we decide to throw out some entries, and will also help us get some stats on the server.
  • Loading branch information...
commit 8c730616f88508f0d1871970b0aa06ed30fba132 1 parent 5ba7d7d
Jason Grout jasongrout authored
Showing with 13 additions and 14 deletions.
  1. +13 −14 db_sqlalchemy.py
27 db_sqlalchemy.py
View
@@ -12,7 +12,7 @@
"""
SQLAlchemy imports
"""
-from sqlalchemy import create_engine, Column, Integer, String
+from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
@@ -39,31 +39,27 @@ def new_exec_msg(self, msg):
"""
See :meth:`db.DB.new_exec_msg`
"""
- message = ExecMessage()
- message.ident = str(uuid.uuid4())
- message.timestamp = str(datetime.utcnow())
-
- retval = None
+ session_id = None
try:
- message.code = str(msg["content"]["code"])
- message.json_message = json.dumps(msg)
+ session_id = str(uuid.uuid4())
+ message = ExecMessage(ident=session_id, code=str(msg["content"]["code"]))
self.dbsession.add(message)
self.dbsession.commit()
- retval = message.ident
except:
- pass
+ session_id = None
- return retval
+ return session_id
def get_exec_msg(self, ident):
"""
See :meth:`db.DB.get_exec_msg`
"""
- msg = self.dbsession.query(ExecMessage.code).filter_by(ident = ident).first()
+ msg = self.dbsession.query(ExecMessage).filter_by(ident = ident).first()
+ if msg:
+ msg.requested = ExecMessage.requested+1
+ self.dbsession.commit()
return msg.code if msg is not None else ""
-
-
Base = declarative_base()
class ExecMessage(Base):
@@ -73,3 +69,6 @@ class ExecMessage(Base):
__tablename__ = "exec_messages"
ident = Column(String, primary_key = True, index = True)
code = Column(String)
+ created = Column(DateTime, default=datetime.utcnow)
+ last_accessed = Column(DateTime, default=datetime.now, onupdate=datetime.utcnow)
+ requested = Column(Integer, default=0)
Please sign in to comment.
Something went wrong with that request. Please try again.