Skip to content

Commit

Permalink
Worker 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-cq committed Feb 25, 2024
1 parent 3dd3b4a commit cc64bdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
1 change: 1 addition & 0 deletions alist_sync/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async def get_files(_path):
_item: Item
_item.parent = _path
if _item.is_dir:
# noinspection PyAsyncCall
asyncio.create_task(
get_files(_item.full_name),
name=f"scan_{_item.full_name}",
Expand Down
39 changes: 7 additions & 32 deletions alist_sync/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
import datetime
import logging
from pathlib import Path
from typing import Literal, Any, Annotated

from pydantic import (
BaseModel,
computed_field,
Field,
AfterValidator,
PlainSerializer,
GetCoreSchemaHandler,
)
from pydantic_core import core_schema
from typing import Literal, Any

from pydantic import BaseModel, computed_field, Field
from pymongo.collection import Collection
from pymongo.database import Database
from alist_sdk.path_lib import AlistPath as _AlistPath
from alist_sdk.path_lib import AlistPathType

from alist_sync.config import cache_dir
from alist_sync.common import sha1
Expand All @@ -35,32 +27,15 @@
logger = logging.getLogger("alist-sync.worker")


class AlistPath(_AlistPath):
@classmethod
def __get_pydantic_core_schema__(
cls,
source_type: Any,
handler: GetCoreSchemaHandler,
):
return core_schema.no_info_after_validator_function(cls, handler(source_type))


A_AlistPath = Annotated[
AlistPath | str,
AfterValidator(lambda x: x if isinstance(x, AlistPath) else AlistPath(x)),
PlainSerializer(lambda x: x.as_uri(), return_type=str),
]


class Worker(BaseModel):
owner: str
created_at: datetime.datetime = datetime.datetime.now()
type: WorkerType
need_backup: bool
backup_dir: A_AlistPath | None = None
backup_dir: AlistPathType | None = None

source_path: A_AlistPath
target_path: A_AlistPath | None = None
source_path: AlistPathType
target_path: AlistPathType | None = None
status: WorkerStatus = "init"
error_info: BaseException | None = None

Expand Down

0 comments on commit cc64bdc

Please sign in to comment.