|
8 | 8 | import subprocess |
9 | 9 | import sys |
10 | 10 | from collections.abc import Callable, Generator, MutableMapping |
11 | | -from datetime import timedelta, datetime |
| 11 | +from datetime import datetime, timedelta, timezone |
12 | 12 | from pathlib import Path |
13 | 13 | from typing import BinaryIO |
14 | 14 |
|
|
58 | 58 | # pylint: disable=redefined-outer-name,too-many-try-statements,import-outside-toplevel,unnecessary-lambda,too-complex,invalid-name |
59 | 59 |
|
60 | 60 | logger = logging.getLogger(__name__) |
61 | | -TEST_JOBS_PURGE_TIMEOUT = timedelta(hours=1, minutes=15) # 15 minutes grace for jobs starting at the end of the hour |
| 61 | + |
| 62 | +"""Preserve resources created during tests for at least this long.""" |
| 63 | +TEST_RESOURCE_PURGE_TIMEOUT = timedelta(hours=1) |
62 | 64 |
|
63 | 65 |
|
64 | 66 | def factory(name, create, remove): |
@@ -1461,8 +1463,15 @@ def delete(dashboard: SDKDashboard) -> None: |
1461 | 1463 | yield from factory("dashboard", create, delete) |
1462 | 1464 |
|
1463 | 1465 |
|
1464 | | -def get_test_purge_time() -> str: |
1465 | | - return (datetime.utcnow() + TEST_JOBS_PURGE_TIMEOUT).strftime("%Y%m%d%H") |
| 1466 | +def get_test_purge_time(timeout: timedelta = TEST_RESOURCE_PURGE_TIMEOUT) -> str: |
| 1467 | + """Purge time for test objects, representing the (UTC-based) hour from which objects may be purged.""" |
| 1468 | + # Note: this code is duplicated in the workflow installer (WorkflowsDeployment) so that it can avoid the |
| 1469 | + # transitive pytest deployment from this module. |
| 1470 | + now = datetime.now(timezone.utc) |
| 1471 | + purge_deadline = now + timeout |
| 1472 | + # Round UP to the next hour boundary: that is when resources will be deleted. |
| 1473 | + purge_hour = purge_deadline + (datetime.min.replace(tzinfo=timezone.utc) - purge_deadline) % timedelta(hours=1) |
| 1474 | + return purge_hour.strftime("%Y%m%d%H") |
1466 | 1475 |
|
1467 | 1476 |
|
1468 | 1477 | def get_purge_suffix() -> str: |
|
0 commit comments