11from datetime import datetime , timedelta
22from enum import Enum
3+ from typing import Annotated
34
45import arrow
6+ from common_library .basic_types import DEFAULT_FACTORY
57from pydantic import BaseModel , Field , NonNegativeInt
68
79from ._base_deferred_handler import StartContext
@@ -23,42 +25,59 @@ class TaskState(str, Enum):
2325
2426
2527class TaskScheduleModel (BaseModel ):
26- timeout : timedelta = Field (
27- ..., description = "Amount of time after which the task execution will time out"
28- )
29- class_unique_reference : ClassUniqueReference = Field (
30- ...,
31- description = "reference to the class containing the code and handlers for the execution of the task" ,
32- )
33- start_context : StartContext = Field (
34- ...,
35- description = "data used to assemble the ``StartContext``" ,
36- )
28+ timeout : Annotated [
29+ timedelta ,
30+ Field (
31+ description = "Amount of time after which the task execution will time out"
32+ ),
33+ ]
34+ class_unique_reference : Annotated [
35+ ClassUniqueReference ,
36+ Field (
37+ description = "reference to the class containing the code and handlers for the execution of the task" ,
38+ ),
39+ ]
40+ start_context : Annotated [
41+ StartContext ,
42+ Field (
43+ description = "data used to assemble the ``StartContext``" ,
44+ ),
45+ ]
3746
38- state : TaskState = Field (
39- ..., description = "represents the execution step of the task"
40- )
47+ state : Annotated [
48+ TaskState , Field ( description = "represents the execution step of the task" )
49+ ]
4150
42- total_attempts : NonNegativeInt = Field (
43- ...,
44- description = "maximum number of attempts before giving up (0 means no retries)" ,
45- )
51+ total_attempts : Annotated [
52+ NonNegativeInt ,
53+ Field (
54+ description = "maximum number of attempts before giving up (0 means no retries)"
55+ ),
56+ ]
4657
47- execution_attempts : NonNegativeInt = Field (
48- ...,
49- description = "remaining attempts to run the code, only retries if this is > 0" ,
50- )
58+ execution_attempts : Annotated [
59+ NonNegativeInt ,
60+ Field (
61+ description = "remaining attempts to run the code, only retries if this is > 0" ,
62+ ),
63+ ]
5164
52- time_started : datetime = Field (
53- default_factory = lambda : arrow .utcnow ().datetime ,
54- description = "time when task schedule was created, used for statistics" ,
55- )
65+ time_started : Annotated [
66+ datetime ,
67+ Field (
68+ default_factory = lambda : arrow .utcnow ().datetime ,
69+ description = "time when task schedule was created, used for statistics" ,
70+ ),
71+ ] = DEFAULT_FACTORY
5672
57- result : TaskExecutionResult | None = Field (
58- default = None ,
59- description = (
60- f"Populated by { TaskState .WORKER } . It always has a value after worker handles it."
61- "Will be used "
73+ result : Annotated [
74+ TaskExecutionResult | None ,
75+ Field (
76+ default = None ,
77+ description = (
78+ f"Populated by { TaskState .WORKER } . It always has a value after worker handles it."
79+ "Will be used "
80+ ),
81+ discriminator = "result_type" ,
6282 ),
63- discriminator = "result_type" ,
64- )
83+ ] = None
0 commit comments