|
14 | 14 | from fractal_server.app.models.v2 import HistoryRun |
15 | 15 | from fractal_server.app.models.v2 import HistoryUnit |
16 | 16 | from fractal_server.app.models.v2 import JobV2 |
| 17 | +from fractal_server.app.models.v2 import Resource |
17 | 18 | from fractal_server.app.models.v2 import TaskGroupV2 |
18 | 19 | from fractal_server.app.models.v2 import WorkflowTaskV2 |
19 | 20 | from fractal_server.app.schemas.v2 import HistoryUnitStatus |
@@ -95,6 +96,7 @@ def execute_tasks( |
95 | 96 | get_runner_config: GetRunnerConfigType, |
96 | 97 | job_type_filters: dict[str, bool], |
97 | 98 | job_attribute_filters: AttributeFilters, |
| 99 | + resource_id: int, |
98 | 100 | ) -> None: |
99 | 101 | logger = get_logger(logger_name=logger_name) |
100 | 102 |
|
@@ -211,13 +213,30 @@ def execute_tasks( |
211 | 213 | f"attribute_filters={job_attribute_filters})." |
212 | 214 | ) |
213 | 215 | logger.info(error_msg) |
214 | | - update_status_of_history_run( |
215 | | - history_run_id=history_run_id, |
216 | | - status=HistoryUnitStatus.FAILED, |
217 | | - db_sync=db, |
218 | | - ) |
| 216 | + with next(get_sync_db()) as db: |
| 217 | + update_status_of_history_run( |
| 218 | + history_run_id=history_run_id, |
| 219 | + status=HistoryUnitStatus.FAILED, |
| 220 | + db_sync=db, |
| 221 | + ) |
219 | 222 | raise JobExecutionError(error_msg) |
220 | 223 |
|
| 224 | + # Fail if the resource is not open for new submissions |
| 225 | + with next(get_sync_db()) as db: |
| 226 | + resource = db.get(Resource, resource_id) |
| 227 | + if resource.prevent_new_submissions: |
| 228 | + error_msg = ( |
| 229 | + f"Cannot run '{task.name}', since the '{resource.name}' " |
| 230 | + "resource is not currently active." |
| 231 | + ) |
| 232 | + logger.info(error_msg) |
| 233 | + update_status_of_history_run( |
| 234 | + history_run_id=history_run_id, |
| 235 | + status=HistoryUnitStatus.FAILED, |
| 236 | + db_sync=db, |
| 237 | + ) |
| 238 | + raise JobExecutionError(error_msg) |
| 239 | + |
221 | 240 | # TASK EXECUTION |
222 | 241 | try: |
223 | 242 | if task.type in [ |
|
0 commit comments