diff options
Diffstat (limited to 'src/zenserver/sessions/sessions.h')
| -rw-r--r-- | src/zenserver/sessions/sessions.h | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/src/zenserver/sessions/sessions.h b/src/zenserver/sessions/sessions.h index db9704430..8f07bfc31 100644 --- a/src/zenserver/sessions/sessions.h +++ b/src/zenserver/sessions/sessions.h @@ -11,6 +11,7 @@ ZEN_THIRD_PARTY_INCLUDES_START #include <tsl/robin_map.h> ZEN_THIRD_PARTY_INCLUDES_END +#include <deque> #include <optional> #include <string> #include <vector> @@ -33,10 +34,20 @@ public: { Oid Id; std::string AppName; + std::string Mode; Oid JobId; CbObject Metadata; DateTime CreatedAt; DateTime UpdatedAt; + DateTime EndedAt{0}; + }; + + struct LogEntry + { + DateTime Timestamp; + std::string Level; + std::string Message; + CbObject Data; }; class Session : public TRefCounted<Session> @@ -51,23 +62,44 @@ public: const SessionInfo& Info() const { return m_Info; } void UpdateMetadata(CbObjectView Metadata) { - // Should this be additive rather than replacing the whole thing? We'll see. m_Info.Metadata = CbObject::Clone(Metadata); m_Info.UpdatedAt = DateTime::Now(); } + void SetEndedAt(DateTime When) { m_Info.EndedAt = When; } + + void AppendLog(LogEntry Entry); + std::vector<LogEntry> GetLogEntries(uint32_t Limit = 0, uint32_t Offset = 0) const; + uint64_t GetLogCount() const; + + /// Returns entries appended after the given cursor and the new cursor value. + /// A cursor of 0 returns all entries currently in the deque. + struct CursorResult + { + std::vector<LogEntry> Entries; + uint64_t Cursor; // new cursor for next poll + uint64_t Count; // current deque size + }; + CursorResult GetLogEntriesAfter(uint64_t AfterCursor) const; + private: - SessionInfo m_Info; - Ref<SessionLog> m_Log; + SessionInfo m_Info; + Ref<SessionLog> m_Log; + mutable RwLock m_LogLock; + std::deque<LogEntry> m_LogEntries; + uint64_t m_TotalAppended = 0; // monotonically increasing counter + + static constexpr uint32_t MaxLogEntries = 10000; }; SessionsService(); ~SessionsService(); - bool RegisterSession(const Oid& SessionId, std::string AppName, const Oid& JobId, CbObjectView Metadata); - bool UpdateSession(const Oid& SessionId, CbObjectView Metadata); - Ref<Session> GetSession(const Oid& SessionId) const; + bool RegisterSession(const Oid& SessionId, std::string AppName, std::string Mode, const Oid& JobId, CbObjectView Metadata); + bool UpdateSession(const Oid& SessionId, CbObjectView Metadata); + Ref<Session> GetSession(const Oid& SessionId) const; std::vector<Ref<Session>> GetSessions() const; + std::vector<Ref<Session>> GetEndedSessions() const; bool RemoveSession(const Oid& SessionId); uint64_t GetSessionCount() const; @@ -77,6 +109,7 @@ private: LoggerRef m_Log; mutable RwLock m_Lock; tsl::robin_map<Oid, Ref<Session>, Oid::Hasher> m_Sessions; + std::vector<Ref<Session>> m_EndedSessions; std::unique_ptr<SessionLogStore> m_SessionLogs; }; |