prefect.server.models.deployments
Functions for interacting with deployment ORM objects. Intended for internal use by the Prefect REST API.
check_work_queues_for_deployment(session, deployment_id)
async
Get work queues that can pick up the specified deployment.
Work queues will pick up a deployment when all of the following are met.
- The deployment has ALL tags that the work queue has (i.e. the work queue's tags must be a subset of the deployment's tags).
- The work queue's specified deployment IDs match the deployment's ID, or the work queue does NOT have specified deployment IDs.
- The work queue's specified flow runners match the deployment's flow runner or the work queue does NOT have a specified flow runner.
Notes on the query:
- Our database currently allows either "null" and empty lists as null values in filters, so we need to catch both cases with "or".
json_contains(A, B)
should be interpreted as "True if A contains B".
Returns:
Type | Description |
---|---|
Sequence[WorkQueue]
|
List[orm_models.WorkQueue]: WorkQueues |
Source code in src/prefect/server/models/deployments.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
|
count_deployments(session, flow_filter=None, flow_run_filter=None, task_run_filter=None, deployment_filter=None, work_pool_filter=None, work_queue_filter=None)
async
Count deployments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
flow_filter |
Optional[FlowFilter]
|
only count deployments whose flows match these criteria |
None
|
flow_run_filter |
Optional[FlowRunFilter]
|
only count deployments whose flow runs match these criteria |
None
|
task_run_filter |
Optional[TaskRunFilter]
|
only count deployments whose task runs match these criteria |
None
|
deployment_filter |
Optional[DeploymentFilter]
|
only count deployment that match these filters |
None
|
work_pool_filter |
Optional[WorkPoolFilter]
|
only count deployments that match these work pool filters |
None
|
work_queue_filter |
Optional[WorkQueueFilter]
|
only count deployments that match these work pool queue filters |
None
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the number of deployments matching filters |
Source code in src/prefect/server/models/deployments.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
create_deployment(db, session, deployment)
async
Upserts a deployment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
a database session |
required |
deployment |
Deployment
|
a deployment model |
required |
Returns:
Type | Description |
---|---|
Optional[Deployment]
|
orm_models.Deployment: the newly-created or updated deployment |
Source code in src/prefect/server/models/deployments.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
create_deployment_schedules(session, deployment_id, schedules)
async
Creates a deployment's schedules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
deployment_id |
UUID
|
a deployment id |
required |
schedules |
List[DeploymentScheduleCreate]
|
a list of deployment schedule create actions |
required |
Source code in src/prefect/server/models/deployments.py
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
|
delete_deployment(session, deployment_id)
async
Delete a deployment by id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
deployment_id |
UUID
|
a deployment id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether or not the deployment was deleted |
Source code in src/prefect/server/models/deployments.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
|
delete_deployment_schedule(session, deployment_id, deployment_schedule_id)
async
Deletes a deployment schedule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
deployment_schedule_id |
UUID
|
a deployment schedule id |
required |
Source code in src/prefect/server/models/deployments.py
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 |
|
delete_schedules_for_deployment(session, deployment_id)
async
Deletes a deployment schedule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
deployment_id |
UUID
|
a deployment id |
required |
Source code in src/prefect/server/models/deployments.py
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 |
|
read_deployment(session, deployment_id)
async
Reads a deployment by id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
deployment_id |
UUID
|
a deployment id |
required |
Returns:
Type | Description |
---|---|
Optional[Deployment]
|
orm_models.Deployment: the deployment |
Source code in src/prefect/server/models/deployments.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
read_deployment_by_name(session, name, flow_name)
async
Reads a deployment by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
name |
str
|
a deployment name |
required |
flow_name |
str
|
the name of the flow the deployment belongs to |
required |
Returns:
Type | Description |
---|---|
Optional[Deployment]
|
orm_models.Deployment: the deployment |
Source code in src/prefect/server/models/deployments.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
read_deployment_schedules(session, deployment_id, deployment_schedule_filter=None)
async
Reads a deployment's schedules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
deployment_id |
UUID
|
a deployment id |
required |
Returns:
Type | Description |
---|---|
List[DeploymentSchedule]
|
list[schemas.core.DeploymentSchedule]: the deployment's schedules |
Source code in src/prefect/server/models/deployments.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
|
read_deployments(session, offset=None, limit=None, flow_filter=None, flow_run_filter=None, task_run_filter=None, deployment_filter=None, work_pool_filter=None, work_queue_filter=None, sort=schemas.sorting.DeploymentSort.NAME_ASC)
async
Read deployments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
offset |
Optional[int]
|
Query offset |
None
|
limit |
Optional[int]
|
Query limit |
None
|
flow_filter |
Optional[FlowFilter]
|
only select deployments whose flows match these criteria |
None
|
flow_run_filter |
Optional[FlowRunFilter]
|
only select deployments whose flow runs match these criteria |
None
|
task_run_filter |
Optional[TaskRunFilter]
|
only select deployments whose task runs match these criteria |
None
|
deployment_filter |
Optional[DeploymentFilter]
|
only select deployment that match these filters |
None
|
work_pool_filter |
Optional[WorkPoolFilter]
|
only select deployments whose work pools match these criteria |
None
|
work_queue_filter |
Optional[WorkQueueFilter]
|
only select deployments whose work pool queues match these criteria |
None
|
sort |
DeploymentSort
|
the sort criteria for selected deployments. Defaults to |
NAME_ASC
|
Returns:
Type | Description |
---|---|
Sequence[Deployment]
|
List[orm_models.Deployment]: deployments |
Source code in src/prefect/server/models/deployments.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
schedule_runs(session, deployment_id, start_time=None, end_time=None, min_time=None, min_runs=None, max_runs=None, auto_scheduled=True)
async
Schedule flow runs for a deployment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
a database session |
required |
deployment_id |
UUID
|
the id of the deployment to schedule |
required |
start_time |
Optional[datetime]
|
the time from which to start scheduling runs |
None
|
end_time |
Optional[datetime]
|
runs will be scheduled until at most this time |
None
|
min_time |
Optional[timedelta]
|
runs will be scheduled until at least this far in the future |
None
|
min_runs |
Optional[int]
|
a minimum amount of runs to schedule |
None
|
max_runs |
Optional[int]
|
a maximum amount of runs to schedule |
None
|
This function will generate the minimum number of runs that satisfy the min and max times, and the min and max counts. Specifically, the following order will be respected.
- Runs will be generated starting on or after the `start_time`
- No more than `max_runs` runs will be generated
- No runs will be generated after `end_time` is reached
- At least `min_runs` runs will be generated
- Runs will be generated until at least `start_time` + `min_time` is reached
Returns:
Type | Description |
---|---|
Sequence[UUID]
|
a list of flow run ids scheduled for the deployment |
Source code in src/prefect/server/models/deployments.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
|
update_deployment(session, deployment_id, deployment)
async
Updates a deployment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
a database session |
required |
deployment_id |
UUID
|
the ID of the deployment to modify |
required |
deployment |
DeploymentUpdate
|
changes to a deployment model |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether the deployment was updated |
Source code in src/prefect/server/models/deployments.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
update_deployment_schedule(session, deployment_id, deployment_schedule_id, schedule)
async
Updates a deployment's schedules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
A database session |
required |
deployment_schedule_id |
UUID
|
a deployment schedule id |
required |
schedule |
DeploymentScheduleUpdate
|
a deployment schedule update action |
required |
Source code in src/prefect/server/models/deployments.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
|