Skip to content

Commit f150ce4

Browse files
committed
feat(models.py): Add EventHistory collection model
Add model with index that will cause documents to expire. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent b4b5dbc commit f150ce4

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

kernelci/api/models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,27 @@ def parse_node_obj(node: Node):
805805
node_dict = node.model_dump()
806806
return submodel.model_validate(node_dict)
807807
raise ValueError(f"Unsupported node kind: {node.kind}")
808+
809+
810+
# eventhistory model
811+
class EventHistory(DatabaseModel):
812+
"""Event history object model"""
813+
timestamp: datetime = Field(
814+
description='Timestamp of event creation',
815+
default_factory=datetime.now
816+
)
817+
data: Dict[str, Any] = Field(
818+
description='Event data'
819+
)
820+
821+
@classmethod
822+
def get_indexes(cls):
823+
"""
824+
Create the index with the expiresAfterSeconds option for the
825+
timestamp field to automatically remove documents after a certain
826+
time.
827+
Default is 86400 seconds (24 hours).
828+
"""
829+
return [
830+
cls.Index('timestamp', {'expireAfterSeconds': 86400}),
831+
]

0 commit comments

Comments
 (0)