mealie/mealie/schema/server/tasks.py
Michael Genson cb15db2d27
feat: re-write get all routes to use pagination (#1424)
rewrite get_all routes to use a pagination pattern to allow for better implementations of search, filter, and sorting on the frontend or by any client without fetching all the data. Additionally we added a CI check for running the Nuxt built to confirm that no TS errors were present. Finally, I had to remove the header support for the Shopping lists as the browser caching based off last_updated header was not allowing it to read recent updates due to how we're handling the updated_at property in the database with nested fields. This will have to be looked at in the future to reimplement. I'm unsure how many other routes have a similar issue. 

Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
2022-06-25 11:39:38 -08:00

52 lines
1.3 KiB
Python

import datetime
import enum
from uuid import UUID
from pydantic import 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
class Config:
orm_mode = True
class ServerTaskPagination(PaginationBase):
items: list[ServerTask]