File tree Expand file tree Collapse file tree
tests/tests_integration/test_api/test_simulators Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020 SimulatorRoutineRevisionWrite ,
2121 SimulatorRoutineWrite ,
2222)
23+ from cognite .client .exceptions import CogniteAPIError
2324from cognite .client .utils ._async_helpers import run_sync
2425from cognite .client .utils ._text import to_snake_case
2526from tests .tests_integration .test_api .test_simulators .seed .data import (
@@ -160,6 +161,22 @@ def seed_simulator_models(
160161 models = cognite_client .simulators .models .list (limit = None )
161162 model = models .get (external_id = model_unique_external_id )
162163
164+ two_hours_ago_ms = int (time .time () * 1000 ) - 2 * 60 * 60 * 1000
165+ stale_ids = [
166+ m .external_id
167+ for m in models
168+ if m .external_id
169+ and m .external_id .startswith ("py_sdk_integration_tests_model_" )
170+ and m .external_id != model_unique_external_id
171+ and m .created_time is not None
172+ and m .created_time < two_hours_ago_ms
173+ ]
174+ if stale_ids :
175+ try :
176+ cognite_client .simulators .models .delete (external_ids = stale_ids )
177+ except CogniteAPIError :
178+ pass
179+
163180 if not model :
164181 new_model = SimulatorModelWrite ._load (
165182 {
You can’t perform that action at this time.
0 commit comments