-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
eric
committed
Dec 16, 2024
1 parent
e427612
commit a0fb548
Showing
7 changed files
with
202 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from datetime import datetime | ||
from typing import List, Union, Optional, Any, Dict | ||
|
||
from pydantic import BaseModel, Field, field_validator | ||
|
||
|
||
class ErrorDetail(BaseModel): | ||
loc: List[Union[str, int]] | ||
msg: str | ||
type: str | ||
|
||
|
||
class ErrorModel(BaseModel): | ||
detail: tuple[ErrorDetail] | ||
|
||
|
||
class ResponseDetail(BaseModel): | ||
status: str | ||
data: List[Any] | ||
message: str | ||
|
||
|
||
class Command(BaseModel): | ||
keyword: Optional[str] = Field(default=None, description="AT命令返回的关键字, 一般是'OK'或者 'ERROR',不传则两个都检测") | ||
timeout: float = Field(default=3, description="等待AT命令回应的超时时间") | ||
|
||
@field_validator('keyword', mode='after', check_fields=False) | ||
@classmethod | ||
def check_message(cls, v: str) -> list[str]: | ||
if v is None: | ||
return ['OK', 'ERROR'] | ||
return [v] | ||
|
||
|
||
class CommandRequest(Command): | ||
command: str | ||
|
||
|
||
class CommandBaseRequest(CommandRequest): | ||
command: str | ||
|
||
|
||
class CommandResponse(BaseModel): | ||
status: str | ||
content: str | ||
|
||
class SendSMSRequest(BaseModel): | ||
country: int | ||
number: int | ||
message: str | ||
|
||
@field_validator('message') | ||
@classmethod | ||
def check_message(cls, v: str) -> str: | ||
if len(v) > 70: | ||
raise ValueError(f"Do not support long sms yet, makesure less than 71 characters.") | ||
return v | ||
|
||
|
||
class ListScheduleJob(BaseModel): | ||
id: str | ||
next_run_time: datetime | ||
trigger: str | ||
func: str | ||
|
||
|
||
class ScheduleSendSMSRequest(SendSMSRequest): | ||
id: str | ||
seconds: int | ||
next_run_time: datetime = Field(default=datetime.now(), description="下次执行的时间") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from zoneinfo import ZoneInfo | ||
|
||
from apscheduler.schedulers.asyncio import AsyncIOScheduler | ||
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore | ||
from services.utils.config_parser import config | ||
|
||
jobstores = { | ||
'default': SQLAlchemyJobStore(url=config.sqlite_url()) | ||
} | ||
|
||
scheduler = AsyncIOScheduler(timezone=ZoneInfo("Asia/Shanghai"), jobstores=jobstores) |