Skip to content

Commit 038df6a

Browse files
authored
Fix the task run method and data type (#228)
1 parent bc942cd commit 038df6a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

backend/app/schemas/task.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3+
from datetime import datetime
4+
35
from backend.app.schemas.base import SchemaBase
46

57

@@ -12,4 +14,4 @@ class GetTask(SchemaBase):
1214
misfire_grace_time: str
1315
coalesce: str
1416
max_instances: str
15-
next_run_time: str
17+
next_run_time: datetime | None

backend/app/services/task_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3+
from datetime import datetime
4+
5+
import pytz
36
from asgiref.sync import sync_to_async
47

58
from backend.app.common.exception import errors
69
from backend.app.common.task import scheduler
10+
from backend.app.core.conf import settings
711
from backend.app.schemas.task import GetTask
8-
from backend.app.utils.timezone import timezone
912

1013

1114
class TaskService:
@@ -55,7 +58,8 @@ def get_task(pk: str):
5558

5659
async def run(self, pk: str):
5760
task = await self.get_task(pk=pk)
58-
scheduler.modify_job(job_id=pk, next_run_time=timezone.now())
61+
# next_run_time 仅适用于 pytz 模块
62+
scheduler.modify_job(job_id=pk, next_run_time=datetime.now(pytz.timezone(settings.DATETIME_TIMEZONE)))
5963
return task
6064

6165
async def pause(self, pk: str):

0 commit comments

Comments
 (0)