Class CrawlSessionRepository

java.lang.Object
ai.pipeline.connector.intake.repository.CrawlSessionRepository
All Implemented Interfaces:
io.quarkus.hibernate.orm.panache.PanacheRepository<CrawlSession>, io.quarkus.hibernate.orm.panache.PanacheRepositoryBase<CrawlSession,Long>

@ApplicationScoped public class CrawlSessionRepository extends Object implements io.quarkus.hibernate.orm.panache.PanacheRepository<CrawlSession>
Repository for crawl session operations.
  • Constructor Details

    • CrawlSessionRepository

      public CrawlSessionRepository()
      Default constructor for CDI.
  • Method Details

    • findById

      public Optional<CrawlSession> findById(String sessionId)
      Find a session by its unique identifier.
      Parameters:
      sessionId - session UUID
      Returns:
      an Optional with the CrawlSession if found; otherwise empty
    • findByConnectorAndCrawl

      public Optional<CrawlSession> findByConnectorAndCrawl(String connectorId, String crawlId)
      Find a session by connector ID and crawl ID.
      Parameters:
      connectorId - connector identifier
      crawlId - client-provided crawl identifier
      Returns:
      an Optional with the CrawlSession if found; otherwise empty
    • findByConnectorId

      public List<CrawlSession> findByConnectorId(String connectorId)
      Find all sessions for a connector.
      Parameters:
      connectorId - connector identifier
      Returns:
      list of sessions owned by the connector (possibly empty)
    • findByAccountId

      public List<CrawlSession> findByAccountId(String accountId)
      Find all sessions for an account.
      Parameters:
      accountId - account identifier
      Returns:
      list of sessions for the account (possibly empty)
    • findByState

      public List<CrawlSession> findByState(String state)
      Find sessions by state.
      Parameters:
      state - session state (e.g., RUNNING, COMPLETED, FAILED)
      Returns:
      list of sessions in the given state (possibly empty)
    • findStaleSessions

      public List<CrawlSession> findStaleSessions(OffsetDateTime cutoffTime)
      Find running sessions whose last heartbeat is older than the cutoff time.
      Parameters:
      cutoffTime - sessions with lastHeartbeat < cutoffTime are considered stale
      Returns:
      list of sessions in RUNNING state that appear stale (possibly empty)
    • updateState

      public void updateState(String sessionId, String state)
      Update the persisted state for a session.
      Parameters:
      sessionId - session UUID
      state - new state value (e.g., RUNNING, COMPLETED, FAILED)
    • updateHeartbeat

      public void updateHeartbeat(String sessionId)
      Update the last heartbeat timestamp for a session to the current time.
      Parameters:
      sessionId - session UUID
    • incrementDocumentsFound

      public void incrementDocumentsFound(String sessionId)
      Increment the counter of documents discovered for the session.
      Parameters:
      sessionId - session UUID
    • incrementDocumentsProcessed

      public void incrementDocumentsProcessed(String sessionId)
      Increment the counter of documents successfully processed for the session.
      Parameters:
      sessionId - session UUID
    • incrementDocumentsFailed

      public void incrementDocumentsFailed(String sessionId)
      Increment the counter of documents that failed processing for the session.
      Parameters:
      sessionId - session UUID
    • incrementDocumentsSkipped

      public void incrementDocumentsSkipped(String sessionId)
      Increment the counter of documents skipped (not processed) for the session.
      Parameters:
      sessionId - session UUID
    • addBytesProcessed

      public void addBytesProcessed(String sessionId, long bytes)
      Add the number of processed bytes to the session total.
      Parameters:
      sessionId - session UUID
      bytes - number of bytes to add (non-negative)
    • completeSession

      public void completeSession(String sessionId, String state)
      Mark a session as completed and set its terminal state.
      Parameters:
      sessionId - session UUID
      state - terminal state to set (e.g., COMPLETED, FAILED, ABORTED)