2019-10-25 12:36:58 +00:00
|
|
|
from mongoengine import (
|
|
|
|
Document,
|
|
|
|
EmbeddedDocument,
|
|
|
|
StringField,
|
|
|
|
DateTimeField,
|
|
|
|
EmbeddedDocumentListField,
|
2022-03-15 14:18:57 +00:00
|
|
|
EmbeddedDocumentField,
|
2019-10-25 12:36:58 +00:00
|
|
|
)
|
|
|
|
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database import Database, strict
|
2022-03-15 14:18:57 +00:00
|
|
|
from apiserver.database.fields import (
|
|
|
|
StrippedStringField,
|
|
|
|
SafeSortedListField,
|
|
|
|
SafeMapField,
|
|
|
|
)
|
|
|
|
from apiserver.database.model import DbModelMixin, AttributedDocument
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database.model.base import ProperDictMixin, GetMixin
|
|
|
|
from apiserver.database.model.company import Company
|
2021-05-03 14:50:25 +00:00
|
|
|
from apiserver.database.model.metadata import MetadataItem
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database.model.task.task import Task
|
2019-10-25 12:36:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Entry(EmbeddedDocument, ProperDictMixin):
|
|
|
|
""" Entry representing a task waiting in the queue """
|
2022-03-15 14:18:57 +00:00
|
|
|
|
2019-10-25 12:36:58 +00:00
|
|
|
task = StringField(required=True, reference_field=Task)
|
2022-03-15 14:18:57 +00:00
|
|
|
""" Task ID """
|
2019-10-25 12:36:58 +00:00
|
|
|
added = DateTimeField(required=True)
|
2022-03-15 14:18:57 +00:00
|
|
|
""" Added to the queue """
|
2019-10-25 12:36:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Queue(DbModelMixin, Document):
|
2022-03-15 14:18:57 +00:00
|
|
|
_field_collation_overrides = {
|
|
|
|
"metadata.": AttributedDocument._numeric_locale,
|
|
|
|
}
|
2019-10-25 12:36:58 +00:00
|
|
|
|
|
|
|
get_all_query_options = GetMixin.QueryParameterOptions(
|
2022-03-15 14:18:57 +00:00
|
|
|
pattern_fields=("name",), list_fields=("tags", "system_tags", "id", "metadata.*"),
|
2019-10-25 12:36:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
meta = {
|
2022-03-15 14:18:57 +00:00
|
|
|
"db_alias": Database.backend,
|
|
|
|
"strict": strict,
|
2019-10-25 12:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
id = StringField(primary_key=True)
|
|
|
|
name = StrippedStringField(
|
|
|
|
required=True, unique_with="company", min_length=3, user_set_allowed=True
|
|
|
|
)
|
|
|
|
company = StringField(required=True, reference_field=Company)
|
|
|
|
created = DateTimeField(required=True)
|
2022-03-15 14:18:57 +00:00
|
|
|
tags = SafeSortedListField(
|
|
|
|
StringField(required=True), default=list, user_set_allowed=True
|
|
|
|
)
|
2020-06-01 10:00:35 +00:00
|
|
|
system_tags = SafeSortedListField(StringField(required=True), user_set_allowed=True)
|
2019-10-25 12:36:58 +00:00
|
|
|
entries = EmbeddedDocumentListField(Entry, default=list)
|
|
|
|
last_update = DateTimeField()
|
2022-03-15 14:18:57 +00:00
|
|
|
metadata = SafeMapField(
|
|
|
|
field=EmbeddedDocumentField(MetadataItem), user_set_allowed=True
|
2021-05-03 14:50:25 +00:00
|
|
|
)
|