@@ -95,68 +95,66 @@ async def add_pilot_stamps(
95
95
96
96
@router .delete ("/" , status_code = HTTPStatus .NO_CONTENT )
97
97
async def delete_pilots (
98
- pilot_stamps : Annotated [
99
- list [str ], Query (description = "Stamps of the pilots we want to delete." )
100
- ],
101
98
pilot_db : PilotAgentsDB ,
102
99
check_permissions : CheckPilotManagementPolicyCallable ,
103
- ):
104
- """Endpoint to delete a pilot.
105
-
106
- If at least one pilot is not found, it WILL rollback.
107
- """
108
- await check_permissions (
109
- action = ActionType .MANAGE_PILOTS ,
110
- )
111
-
112
- try :
113
- await delete_pilots_by_stamps (pilot_db = pilot_db , pilot_stamps = pilot_stamps )
114
- except PilotNotFoundError as e :
115
- raise HTTPException (
116
- status_code = status .HTTP_400_BAD_REQUEST ,
117
- detail = "At least one pilot has not been found." ,
118
- ) from e
119
-
120
-
121
- @router .delete ("/management/pilot/interval" , status_code = HTTPStatus .NO_CONTENT )
122
- async def clear_pilots (
123
- pilot_db : PilotAgentsDB ,
100
+ pilot_stamps : Annotated [
101
+ list [str ] | None , Query (description = "Stamps of the pilots we want to delete." )
102
+ ] = None ,
124
103
age_in_days : Annotated [
125
- int ,
104
+ int | None ,
126
105
Query (
127
106
description = (
128
107
"The number of days that define the maximum age of pilots to be deleted."
129
108
"Pilots older than this age will be considered for deletion."
130
109
)
131
110
),
132
- ],
133
- check_permissions : CheckPilotManagementPolicyCallable ,
111
+ ] = None ,
134
112
delete_only_aborted : Annotated [
135
113
bool ,
136
114
Query (
137
115
description = (
138
116
"Flag indicating whether to only delete pilots whose status is 'Aborted'."
139
117
"If set to True, only pilots with the 'Aborted' status will be deleted."
140
- "It is set by default as True to avoid any mistake."
118
+ "It is set by default as True to avoid any mistake." ,
119
+ "This flag is only used for deletion by time." ,
141
120
)
142
121
),
143
122
] = False ,
144
123
):
145
- """Endpoint for DIRAC to delete all pilots that lived more than age_in_days."""
146
- await check_permissions (ActionType .MANAGE_PILOTS )
124
+ """Endpoint to delete a pilot.
125
+
126
+ Two features:
127
+
128
+ 1. Or you provide pilot_stamps, so you can delete pilots by their stamp
129
+ 2. Or you provide age_in_days, so you can delete pilots that lived more than age_in_days days.
147
130
148
- if age_in_days < 0 :
131
+ If deleting by stamps, if at least one pilot is not found, it WILL rollback.
132
+ """
133
+ await check_permissions (
134
+ action = ActionType .MANAGE_PILOTS ,
135
+ )
136
+
137
+ if pilot_stamps :
138
+ try :
139
+ await delete_pilots_by_stamps (pilot_db = pilot_db , pilot_stamps = pilot_stamps )
140
+ except PilotNotFoundError as e :
141
+ raise HTTPException (
142
+ status_code = status .HTTP_400_BAD_REQUEST ,
143
+ detail = "At least one pilot has not been found." ,
144
+ ) from e
145
+
146
+ elif age_in_days :
147
+ await clear_pilots_bl (
148
+ pilot_db = pilot_db ,
149
+ age_in_days = age_in_days ,
150
+ delete_only_aborted = delete_only_aborted ,
151
+ )
152
+ else :
149
153
raise HTTPException (
150
154
status_code = status .HTTP_400_BAD_REQUEST ,
151
- detail = "age_in_days must be positive ." ,
155
+ detail = "You must provide either age_in_days or pilot_stamps ." ,
152
156
)
153
157
154
- await clear_pilots_bl (
155
- pilot_db = pilot_db ,
156
- age_in_days = age_in_days ,
157
- delete_only_aborted = delete_only_aborted ,
158
- )
159
-
160
158
161
159
EXAMPLE_UPDATE_FIELDS = {
162
160
"Update the BenchMark field" : {
0 commit comments