5
5
from pathlib import Path
6
6
from typing import TYPE_CHECKING , Any , ClassVar , Optional , Union
7
7
8
- import pendulum
9
8
import sqlalchemy as sa
10
9
from sqlalchemy import FetchedValue
11
10
from sqlalchemy .dialects import postgresql
46
45
Timestamp ,
47
46
)
48
47
from prefect .server .utilities .encryption import decrypt_fernet , encrypt_fernet
48
+ from prefect .types ._datetime import DateTime , now
49
49
from prefect .utilities .names import generate_slug
50
50
51
- if TYPE_CHECKING :
52
- DateTime = pendulum .DateTime
53
-
54
51
# for 'plain JSON' columns, use the postgresql variant (which comes with an
55
52
# extra operator) and fall back to the generic JSON variant for SQLite
56
53
sa_JSON : postgresql .JSON = postgresql .JSON ().with_variant (sa .JSON (), "sqlite" )
@@ -89,7 +86,7 @@ class Base(DeclarativeBase):
89
86
),
90
87
type_annotation_map = {
91
88
uuid .UUID : UUID ,
92
- pendulum . DateTime : Timestamp ,
89
+ DateTime : Timestamp ,
93
90
},
94
91
)
95
92
@@ -121,17 +118,17 @@ def __tablename__(cls) -> str:
121
118
default = uuid .uuid4 ,
122
119
)
123
120
124
- created : Mapped [pendulum . DateTime ] = mapped_column (
125
- server_default = sa .func .now (), default = lambda : pendulum . now ("UTC" )
121
+ created : Mapped [DateTime ] = mapped_column (
122
+ server_default = sa .func .now (), default = lambda : now ("UTC" )
126
123
)
127
124
128
125
# onupdate is only called when statements are actually issued
129
126
# against the database. until COMMIT is issued, this column
130
127
# will not be updated
131
- updated : Mapped [pendulum . DateTime ] = mapped_column (
128
+ updated : Mapped [DateTime ] = mapped_column (
132
129
index = True ,
133
130
server_default = sa .func .now (),
134
- default = lambda : pendulum . now ("UTC" ),
131
+ default = lambda : now ("UTC" ),
135
132
onupdate = sa .func .now (),
136
133
server_onupdate = FetchedValue (),
137
134
)
@@ -170,8 +167,8 @@ class FlowRunState(Base):
170
167
type : Mapped [schemas .states .StateType ] = mapped_column (
171
168
sa .Enum (schemas .states .StateType , name = "state_type" ), index = True
172
169
)
173
- timestamp : Mapped [pendulum . DateTime ] = mapped_column (
174
- server_default = sa .func .now (), default = lambda : pendulum . now ("UTC" )
170
+ timestamp : Mapped [DateTime ] = mapped_column (
171
+ server_default = sa .func .now (), default = lambda : now ("UTC" )
175
172
)
176
173
name : Mapped [str ] = mapped_column (index = True )
177
174
message : Mapped [Optional [str ]]
@@ -235,8 +232,8 @@ class TaskRunState(Base):
235
232
type : Mapped [schemas .states .StateType ] = mapped_column (
236
233
sa .Enum (schemas .states .StateType , name = "state_type" ), index = True
237
234
)
238
- timestamp : Mapped [pendulum . DateTime ] = mapped_column (
239
- server_default = sa .func .now (), default = lambda : pendulum . now ("UTC" )
235
+ timestamp : Mapped [DateTime ] = mapped_column (
236
+ server_default = sa .func .now (), default = lambda : now ("UTC" )
240
237
)
241
238
name : Mapped [str ] = mapped_column (index = True )
242
239
message : Mapped [Optional [str ]]
@@ -358,7 +355,7 @@ class TaskRunStateCache(Base):
358
355
"""
359
356
360
357
cache_key : Mapped [str ] = mapped_column ()
361
- cache_expiration : Mapped [Optional [pendulum . DateTime ]]
358
+ cache_expiration : Mapped [Optional [DateTime ]]
362
359
task_run_state_id : Mapped [uuid .UUID ]
363
360
364
361
@declared_attr .directive
@@ -385,12 +382,12 @@ class Run(Base):
385
382
sa .Enum (schemas .states .StateType , name = "state_type" )
386
383
)
387
384
state_name : Mapped [Optional [str ]]
388
- state_timestamp : Mapped [Optional [pendulum . DateTime ]]
385
+ state_timestamp : Mapped [Optional [DateTime ]]
389
386
run_count : Mapped [int ] = mapped_column (server_default = "0" , default = 0 )
390
- expected_start_time : Mapped [Optional [pendulum . DateTime ]]
391
- next_scheduled_start_time : Mapped [Optional [pendulum . DateTime ]]
392
- start_time : Mapped [Optional [pendulum . DateTime ]]
393
- end_time : Mapped [Optional [pendulum . DateTime ]]
387
+ expected_start_time : Mapped [Optional [DateTime ]]
388
+ next_scheduled_start_time : Mapped [Optional [DateTime ]]
389
+ start_time : Mapped [Optional [DateTime ]]
390
+ end_time : Mapped [Optional [DateTime ]]
394
391
total_run_time : Mapped [datetime .timedelta ] = mapped_column (
395
392
server_default = "0" , default = datetime .timedelta (0 )
396
393
)
@@ -403,7 +400,7 @@ def estimated_run_time(self) -> datetime.timedelta:
403
400
if self .state_type and self .state_type == schemas .states .StateType .RUNNING :
404
401
if TYPE_CHECKING :
405
402
assert self .state_timestamp is not None
406
- return self .total_run_time + (pendulum . now ("UTC" ) - self .state_timestamp )
403
+ return self .total_run_time + (now ("UTC" ) - self .state_timestamp )
407
404
else :
408
405
return self .total_run_time
409
406
@@ -445,10 +442,10 @@ def estimated_start_time_delta(self) -> datetime.timedelta:
445
442
elif (
446
443
self .start_time is None
447
444
and self .expected_start_time
448
- and self .expected_start_time < pendulum . now ("UTC" )
445
+ and self .expected_start_time < now ("UTC" )
449
446
and self .state_type not in schemas .states .TERMINAL_STATES
450
447
):
451
- return pendulum . now ("UTC" ) - self .expected_start_time
448
+ return now ("UTC" ) - self .expected_start_time
452
449
else :
453
450
return datetime .timedelta (0 )
454
451
@@ -660,7 +657,7 @@ class TaskRun(Run):
660
657
task_key : Mapped [str ] = mapped_column ()
661
658
dynamic_key : Mapped [str ] = mapped_column ()
662
659
cache_key : Mapped [Optional [str ]]
663
- cache_expiration : Mapped [Optional [pendulum . DateTime ]]
660
+ cache_expiration : Mapped [Optional [DateTime ]]
664
661
task_version : Mapped [Optional [str ]]
665
662
flow_run_run_count : Mapped [int ] = mapped_column (server_default = "0" , default = 0 )
666
663
empirical_policy : Mapped [schemas .core .TaskRunPolicy ] = mapped_column (
@@ -803,7 +800,7 @@ class Deployment(Base):
803
800
path : Mapped [Optional [str ]]
804
801
entrypoint : Mapped [Optional [str ]]
805
802
806
- last_polled : Mapped [Optional [pendulum . DateTime ]]
803
+ last_polled : Mapped [Optional [DateTime ]]
807
804
status : Mapped [DeploymentStatus ] = mapped_column (
808
805
sa .Enum (DeploymentStatus , name = "deployment_status" ),
809
806
default = DeploymentStatus .NOT_READY ,
@@ -913,7 +910,7 @@ class Log(Base):
913
910
message : Mapped [str ] = mapped_column (sa .Text )
914
911
915
912
# The client-side timestamp of this logged statement.
916
- timestamp : Mapped [pendulum . DateTime ] = mapped_column (index = True )
913
+ timestamp : Mapped [DateTime ] = mapped_column (index = True )
917
914
918
915
__table_args__ : Any = (
919
916
sa .Index (
@@ -1104,7 +1101,7 @@ class WorkQueue(Base):
1104
1101
concurrency_limit : Mapped [Optional [int ]]
1105
1102
priority : Mapped [int ]
1106
1103
1107
- last_polled : Mapped [Optional [pendulum . DateTime ]]
1104
+ last_polled : Mapped [Optional [DateTime ]]
1108
1105
status : Mapped [WorkQueueStatus ] = mapped_column (
1109
1106
sa .Enum (WorkQueueStatus , name = "work_queue_status" ),
1110
1107
default = WorkQueueStatus .NOT_READY ,
@@ -1150,7 +1147,7 @@ class WorkPool(Base):
1150
1147
default = WorkPoolStatus .NOT_READY ,
1151
1148
server_default = WorkPoolStatus .NOT_READY ,
1152
1149
)
1153
- last_transitioned_status_at : Mapped [Optional [pendulum . DateTime ]]
1150
+ last_transitioned_status_at : Mapped [Optional [DateTime ]]
1154
1151
last_status_event_id : Mapped [Optional [uuid .UUID ]]
1155
1152
1156
1153
__table_args__ : Any = (sa .UniqueConstraint ("name" ),)
@@ -1164,8 +1161,8 @@ class Worker(Base):
1164
1161
)
1165
1162
1166
1163
name : Mapped [str ]
1167
- last_heartbeat_time : Mapped [pendulum . DateTime ] = mapped_column (
1168
- server_default = sa .func .now (), default = lambda : pendulum . now ("UTC" )
1164
+ last_heartbeat_time : Mapped [DateTime ] = mapped_column (
1165
+ server_default = sa .func .now (), default = lambda : now ("UTC" )
1169
1166
)
1170
1167
heartbeat_interval_seconds : Mapped [Optional [int ]]
1171
1168
@@ -1194,8 +1191,8 @@ class Agent(Base):
1194
1191
sa .ForeignKey ("work_queue.id" ), index = True
1195
1192
)
1196
1193
1197
- last_activity_time : Mapped [pendulum . DateTime ] = mapped_column (
1198
- server_default = sa .func .now (), default = lambda : pendulum . now ("UTC" )
1194
+ last_activity_time : Mapped [DateTime ] = mapped_column (
1195
+ server_default = sa .func .now (), default = lambda : now ("UTC" )
1199
1196
)
1200
1197
1201
1198
__table_args__ : Any = (sa .UniqueConstraint ("name" ),)
@@ -1249,7 +1246,7 @@ class FlowRunInput(Base):
1249
1246
class CsrfToken (Base ):
1250
1247
token : Mapped [str ]
1251
1248
client : Mapped [str ] = mapped_column (unique = True )
1252
- expiration : Mapped [pendulum . DateTime ]
1249
+ expiration : Mapped [DateTime ]
1253
1250
1254
1251
1255
1252
class Automation (Base ):
@@ -1314,14 +1311,14 @@ class AutomationBucket(Base):
1314
1311
1315
1312
last_event : Mapped [Optional [ReceivedEvent ]] = mapped_column (Pydantic (ReceivedEvent ))
1316
1313
1317
- start : Mapped [pendulum . DateTime ]
1318
- end : Mapped [pendulum . DateTime ]
1314
+ start : Mapped [DateTime ]
1315
+ end : Mapped [DateTime ]
1319
1316
1320
1317
count : Mapped [int ]
1321
1318
1322
1319
last_operation : Mapped [Optional [str ]]
1323
1320
1324
- triggered_at : Mapped [Optional [pendulum . DateTime ]]
1321
+ triggered_at : Mapped [Optional [DateTime ]]
1325
1322
1326
1323
1327
1324
class AutomationRelatedResource (Base ):
@@ -1367,7 +1364,7 @@ class CompositeTriggerChildFiring(Base):
1367
1364
1368
1365
child_trigger_id : Mapped [uuid .UUID ]
1369
1366
child_firing_id : Mapped [uuid .UUID ]
1370
- child_fired_at : Mapped [Optional [pendulum . DateTime ]]
1367
+ child_fired_at : Mapped [Optional [DateTime ]]
1371
1368
child_firing : Mapped [Firing ] = mapped_column (Pydantic (Firing ))
1372
1369
1373
1370
@@ -1383,7 +1380,7 @@ class AutomationEventFollower(Base):
1383
1380
scope : Mapped [str ] = mapped_column (default = "" , index = True )
1384
1381
leader_event_id : Mapped [uuid .UUID ] = mapped_column (index = True )
1385
1382
follower_event_id : Mapped [uuid .UUID ]
1386
- received : Mapped [pendulum . DateTime ] = mapped_column (index = True )
1383
+ received : Mapped [DateTime ] = mapped_column (index = True )
1387
1384
follower : Mapped [ReceivedEvent ] = mapped_column (Pydantic (ReceivedEvent ))
1388
1385
1389
1386
@@ -1407,7 +1404,7 @@ def __tablename__(cls) -> str:
1407
1404
sa .Index ("ix_events__event_related_occurred" , "event" , "related" , "occurred" ),
1408
1405
)
1409
1406
1410
- occurred : Mapped [pendulum . DateTime ]
1407
+ occurred : Mapped [DateTime ]
1411
1408
event : Mapped [str ] = mapped_column (sa .Text ())
1412
1409
resource_id : Mapped [str ] = mapped_column (sa .Text ())
1413
1410
resource : Mapped [dict [str , Any ]] = mapped_column (JSON ())
@@ -1418,8 +1415,8 @@ def __tablename__(cls) -> str:
1418
1415
JSON (), server_default = "[]" , default = list
1419
1416
)
1420
1417
payload : Mapped [dict [str , Any ]] = mapped_column (JSON ())
1421
- received : Mapped [pendulum . DateTime ]
1422
- recorded : Mapped [pendulum . DateTime ]
1418
+ received : Mapped [DateTime ]
1419
+ recorded : Mapped [DateTime ]
1423
1420
follows : Mapped [Optional [uuid .UUID ]]
1424
1421
1425
1422
@@ -1436,7 +1433,7 @@ def __tablename__(cls) -> str:
1436
1433
),
1437
1434
)
1438
1435
1439
- occurred : Mapped [pendulum . DateTime ]
1436
+ occurred : Mapped [DateTime ]
1440
1437
resource_id : Mapped [str ] = mapped_column (sa .Text ())
1441
1438
resource_role : Mapped [str ] = mapped_column (sa .Text ())
1442
1439
resource : Mapped [dict [str , Any ]] = mapped_column (sa_JSON )
0 commit comments