Skip to content

Commit 86d3df5

Browse files
authored
[CVAT] Reduce logs about failed lock acquisitions (#3570)
1 parent 223d6d1 commit 86d3df5

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

packages/examples/cvat/exchange-oracle/debug.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,20 @@ def patched_get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
6666
logger.debug(f"DEV: Local manifests: {format_sequence(minio_manifests)}")
6767

6868
candidate_files = [
69-
fn for fn in minio_manifests if PurePosixPath(fn).name == f"{escrow_address}.json"
69+
fn
70+
for fn in minio_manifests
71+
if (
72+
"/" in escrow_address
73+
and fn == f"{escrow_address}.json"
74+
or PurePosixPath(fn).name == f"{escrow_address}.json"
75+
)
7076
]
7177
if not candidate_files:
7278
return original_get_escrow(ChainId(chain_id), escrow_address)
7379
elif len(candidate_files) != 1:
7480
raise Exception(
7581
"Can't select local manifest to be used for escrow '{}'"
76-
" - several manifests math: {}".format(
82+
" - several manifests match: {}".format(
7783
escrow_address, format_sequence(candidate_files)
7884
)
7985
)
@@ -92,7 +98,7 @@ def patched_get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
9298
token="HMT", # noqa: S106
9399
total_funded_amount=10,
94100
created_at=datetime.datetime(2023, 1, 1, tzinfo=datetime.timezone.utc),
95-
manifest_url=(f"http://{Config.storage_config.endpoint_url}/manifests/{manifest_file}"),
101+
manifest=(f"http://{Config.storage_config.endpoint_url}/manifests/{manifest_file}"),
96102
)
97103

98104
logger.info(f"DEV: Using local manifest '{manifest_file}' for escrow '{escrow_address}'")

packages/examples/cvat/exchange-oracle/src/crons/cvat/state_trackers.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from contextlib import suppress
32

43
from sqlalchemy.orm import Session
54

@@ -31,7 +30,7 @@ def process_incoming_cvat_webhooks(logger: logging.Logger, session: Session) ->
3130

3231
for webhook in webhooks:
3332
try:
34-
with session.begin_nested():
33+
with session.begin_nested(), db.suppress(db_errors.LockNotAvailable):
3534
cvat_webhook_handler(webhook, session)
3635
cvat_service.incoming_webhooks.handle_webhook_success(
3736
session, webhook_id=webhook.id
@@ -131,10 +130,7 @@ def _reset_job_after_assignment(session: Session, assignment: cvat_models.Assign
131130
)
132131

133132
for assignment in assignments:
134-
with (
135-
session.begin_nested(),
136-
suppress(db_errors.LockNotAvailable),
137-
):
133+
with session.begin_nested(), db.suppress(db_errors.LockNotAvailable):
138134
cvat_service.get_jobs_by_cvat_id(
139135
session,
140136
cvat_ids=[assignment.cvat_job_id],
@@ -161,10 +157,7 @@ def _reset_job_after_assignment(session: Session, assignment: cvat_models.Assign
161157
)
162158

163159
for assignment in assignments:
164-
with (
165-
session.begin_nested(),
166-
suppress(db_errors.LockNotAvailable),
167-
):
160+
with session.begin_nested(), db.suppress(db_errors.LockNotAvailable):
168161
cvat_service.get_jobs_by_cvat_id(
169162
session,
170163
cvat_ids=[assignment.cvat_job_id],
@@ -189,10 +182,7 @@ def _reset_job_after_assignment(session: Session, assignment: cvat_models.Assign
189182

190183
for assignment in assignments:
191184
if assignment.job.project.status != ProjectStatuses.annotation:
192-
with (
193-
session.begin_nested(),
194-
suppress(db_errors.LockNotAvailable),
195-
):
185+
with session.begin_nested(), db.suppress(db_errors.LockNotAvailable):
196186
cvat_service.get_jobs_by_cvat_id(
197187
session,
198188
cvat_ids=[assignment.cvat_job_id],

packages/examples/cvat/exchange-oracle/src/db/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from contextlib import contextmanager
22
from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypeVar
3-
from uuid import uuid4
43

54
import sqlalchemy
65
from psycopg2.errors import Error

packages/examples/cvat/recording-oracle/debug.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,20 @@ def patched_get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
3232
logger.debug(f"DEV: Local manifests: {format_sequence(minio_manifests)}")
3333

3434
candidate_files = [
35-
fn for fn in minio_manifests if PurePosixPath(fn).name == f"{escrow_address}.json"
35+
fn
36+
for fn in minio_manifests
37+
if (
38+
"/" in escrow_address
39+
and fn == f"{escrow_address}.json"
40+
or PurePosixPath(fn).name == f"{escrow_address}.json"
41+
)
3642
]
3743
if not candidate_files:
3844
return original_get_escrow(ChainId(chain_id), escrow_address)
3945
if len(candidate_files) != 1:
4046
raise Exception(
4147
f"Can't select local manifest to be used for escrow '{escrow_address}'"
42-
f" - several manifests math: {format_sequence(candidate_files)}"
48+
f" - several manifests match: {format_sequence(candidate_files)}"
4349
)
4450

4551
manifest_file = candidate_files[0]
@@ -56,7 +62,7 @@ def patched_get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
5662
token="HMT", # noqa: S106
5763
total_funded_amount=10,
5864
created_at=datetime.datetime(2023, 1, 1, tzinfo=datetime.timezone.utc),
59-
manifest_url=(f"http://{Config.storage_config.endpoint_url}/manifests/{manifest_file}"),
65+
manifest=(f"http://{Config.storage_config.endpoint_url}/manifests/{manifest_file}"),
6066
)
6167

6268
logger.info(f"DEV: Using local manifest '{manifest_file}' for escrow '{escrow_address}'")

0 commit comments

Comments
 (0)