mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-29 01:59:40 +02:00
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend and End-to-End Tests (push) Waiting to run
* bumped pydantic
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import datetime
|
|
import enum
|
|
from uuid import UUID
|
|
|
|
from pydantic import ConfigDict, Field
|
|
|
|
from mealie.schema._mealie import MealieModel
|
|
from mealie.schema.response.pagination import PaginationBase
|
|
|
|
|
|
class ServerTaskNames(str, enum.Enum):
|
|
default = "Background Task"
|
|
backup_task = "Database Backup"
|
|
bulk_recipe_import = "Bulk Recipe Import"
|
|
|
|
|
|
class ServerTaskStatus(str, enum.Enum):
|
|
running = "running"
|
|
finished = "finished"
|
|
failed = "failed"
|
|
|
|
|
|
class ServerTaskCreate(MealieModel):
|
|
group_id: UUID
|
|
name: ServerTaskNames = ServerTaskNames.default
|
|
created_at: datetime.datetime = Field(default_factory=datetime.datetime.now)
|
|
status: ServerTaskStatus = ServerTaskStatus.running
|
|
log: str = ""
|
|
|
|
def set_running(self) -> None:
|
|
self.status = ServerTaskStatus.running
|
|
|
|
def set_finished(self) -> None:
|
|
self.status = ServerTaskStatus.finished
|
|
|
|
def set_failed(self) -> None:
|
|
self.status = ServerTaskStatus.failed
|
|
|
|
def append_log(self, message: str) -> None:
|
|
# Prefix with Timestamp and append new line and join to log
|
|
self.log += f"{datetime.datetime.now()}: {message}\n"
|
|
|
|
|
|
class ServerTask(ServerTaskCreate):
|
|
id: int
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class ServerTaskPagination(PaginationBase):
|
|
items: list[ServerTask]
|