Archivist is a background event loop responsible for overseeing the archival of incidents that have reached a conclusion. It periodically examines the incidents in memory and processes them to be archived if they meet the determined criteria.
The eventLoop
function drives the Archivist, iterating over the currently tracked incidents and determining whether they are eligible for archival based on their state.
An incident is considered ready for archival when the ARCHIVE
action from the incident's finite state machine is successful. This typically means the incident has been completed or canceled and all necessary follow-up actions have been completed.
Upon determining that an incident should be archived:
- The incident's data is archived in the database.
- If database archival is successful, the incident is removed from
robot.incidents
tracking. - The associated chat room (if any) is archived through the
robot.adapter.archiveRoom
method.
Archivist also removes incidents from memory if the state of an incident is found to be already Archived
for some reason due to any unforeseen errors or discrepancies.
The use of Archivist is mostly automated and requires minimal manual intervention once configured:
- Starting: To initialize the Archivist event loop, invoke the
startArchivist
function, which sets up a repeating interval task usingsetInterval
to triggereventLoop
. - Stopping: To terminate the event loop, use the
stopArchivist
function to clear the interval set bystartArchivist
.