Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/examples/cvat/exchange-oracle/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ def patched_get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
logger.debug(f"DEV: Local manifests: {format_sequence(minio_manifests)}")

candidate_files = [
fn for fn in minio_manifests if PurePosixPath(fn).name == f"{escrow_address}.json"
fn
for fn in minio_manifests
if (
"/" in escrow_address
and fn == f"{escrow_address}.json"
or PurePosixPath(fn).name == f"{escrow_address}.json"
)
]
if not candidate_files:
return original_get_escrow(ChainId(chain_id), escrow_address)
elif len(candidate_files) != 1:
raise Exception(
"Can't select local manifest to be used for escrow '{}'"
" - several manifests math: {}".format(
" - several manifests match: {}".format(
escrow_address, format_sequence(candidate_files)
)
)
Expand All @@ -92,7 +98,7 @@ def patched_get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
token="HMT", # noqa: S106
total_funded_amount=10,
created_at=datetime.datetime(2023, 1, 1, tzinfo=datetime.timezone.utc),
manifest_url=(f"http://{Config.storage_config.endpoint_url}/manifests/{manifest_file}"),
manifest=(f"http://{Config.storage_config.endpoint_url}/manifests/{manifest_file}"),
)

logger.info(f"DEV: Using local manifest '{manifest_file}' for escrow '{escrow_address}'")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from contextlib import suppress

from sqlalchemy.orm import Session

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

for webhook in webhooks:
try:
with session.begin_nested():
with session.begin_nested(), db.suppress(db_errors.LockNotAvailable):
cvat_webhook_handler(webhook, session)
cvat_service.incoming_webhooks.handle_webhook_success(
session, webhook_id=webhook.id
Expand Down Expand Up @@ -131,10 +130,7 @@ def _reset_job_after_assignment(session: Session, assignment: cvat_models.Assign
)

for assignment in assignments:
with (
session.begin_nested(),
suppress(db_errors.LockNotAvailable),
):
with session.begin_nested(), db.suppress(db_errors.LockNotAvailable):
cvat_service.get_jobs_by_cvat_id(
session,
cvat_ids=[assignment.cvat_job_id],
Expand All @@ -161,10 +157,7 @@ def _reset_job_after_assignment(session: Session, assignment: cvat_models.Assign
)

for assignment in assignments:
with (
session.begin_nested(),
suppress(db_errors.LockNotAvailable),
):
with session.begin_nested(), db.suppress(db_errors.LockNotAvailable):
cvat_service.get_jobs_by_cvat_id(
session,
cvat_ids=[assignment.cvat_job_id],
Expand All @@ -189,10 +182,7 @@ def _reset_job_after_assignment(session: Session, assignment: cvat_models.Assign

for assignment in assignments:
if assignment.job.project.status != ProjectStatuses.annotation:
with (
session.begin_nested(),
suppress(db_errors.LockNotAvailable),
):
with session.begin_nested(), db.suppress(db_errors.LockNotAvailable):
cvat_service.get_jobs_by_cvat_id(
session,
cvat_ids=[assignment.cvat_job_id],
Expand Down
1 change: 0 additions & 1 deletion packages/examples/cvat/exchange-oracle/src/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypeVar
from uuid import uuid4

import sqlalchemy
from psycopg2.errors import Error
Expand Down
12 changes: 9 additions & 3 deletions packages/examples/cvat/recording-oracle/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ def patched_get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
logger.debug(f"DEV: Local manifests: {format_sequence(minio_manifests)}")

candidate_files = [
fn for fn in minio_manifests if PurePosixPath(fn).name == f"{escrow_address}.json"
fn
for fn in minio_manifests
if (
"/" in escrow_address
and fn == f"{escrow_address}.json"
or PurePosixPath(fn).name == f"{escrow_address}.json"
)
]
if not candidate_files:
return original_get_escrow(ChainId(chain_id), escrow_address)
if len(candidate_files) != 1:
raise Exception(
f"Can't select local manifest to be used for escrow '{escrow_address}'"
f" - several manifests math: {format_sequence(candidate_files)}"
f" - several manifests match: {format_sequence(candidate_files)}"
)

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

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