Skip to content

Commit

Permalink
[refactoring] split queue.py in 3 modules (#2930)
Browse files Browse the repository at this point in the history
* extract lock

* move metrics

* move queue

* new_queue -> queue

* fix

* fix
  • Loading branch information
severo authored Jun 20, 2024
1 parent e086100 commit d19ec87
Show file tree
Hide file tree
Showing 51 changed files with 567 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import logging

from libcommon.queue import JobTotalMetricDocument, Queue, WorkerSizeJobsCountDocument
from libcommon.queue.jobs import Queue
from libcommon.queue.metrics import JobTotalMetricDocument, WorkerSizeJobsCountDocument


def collect_queue_metrics() -> None:
Expand Down
2 changes: 1 addition & 1 deletion jobs/cache_maintenance/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from collections.abc import Iterator

from libcommon.queue import _clean_queue_database
from libcommon.queue.utils import _clean_queue_database
from libcommon.resources import CacheMongoResource, QueueMongoResource
from libcommon.simple_cache import _clean_cache_database
from pytest import MonkeyPatch, fixture
Expand Down
9 changes: 2 additions & 7 deletions jobs/cache_maintenance/tests/test_collect_queue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
from unittest.mock import patch

import pytest
from libcommon.queue import (
JobsCountByWorkerSize,
JobsTotalByTypeAndStatus,
JobTotalMetricDocument,
Queue,
WorkerSizeJobsCountDocument,
)
from libcommon.queue.jobs import JobsCountByWorkerSize, JobsTotalByTypeAndStatus, Queue
from libcommon.queue.metrics import JobTotalMetricDocument, WorkerSizeJobsCountDocument

from cache_maintenance.queue_metrics import collect_queue_metrics, collect_worker_size_jobs_count

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Mapping
from typing import Any, Optional

from libcommon.queue import JobDocument
from libcommon.queue.jobs import JobDocument
from libcommon.simple_cache import CachedResponseDocument
from mongoengine.connection import get_db

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

from libcommon.constants import QUEUE_COLLECTION_JOBS, QUEUE_MONGOENGINE_ALIAS
from libcommon.queue import JobDocument
from libcommon.queue.jobs import JobDocument
from mongoengine.connection import get_db

from mongodb_migration.check import check_documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

from libcommon.constants import QUEUE_COLLECTION_JOBS, QUEUE_MONGOENGINE_ALIAS
from libcommon.queue import JobDocument
from libcommon.queue.jobs import JobDocument
from mongoengine.connection import get_db

from mongodb_migration.check import check_documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

from libcommon.constants import QUEUE_COLLECTION_LOCKS, QUEUE_MONGOENGINE_ALIAS
from libcommon.queue import Lock
from libcommon.queue.lock import Lock
from mongoengine.connection import get_db

from mongodb_migration.check import check_documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
QUEUE_MONGOENGINE_ALIAS,
)
from libcommon.processing_graph import specification
from libcommon.queue import JobDocument
from libcommon.queue.jobs import JobDocument
from mongoengine.connection import get_db

from mongodb_migration.check import check_documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

from libcommon.constants import QUEUE_COLLECTION_LOCKS, QUEUE_MONGOENGINE_ALIAS
from libcommon.queue import Lock
from libcommon.queue.lock import Lock
from mongoengine.connection import get_db

from mongodb_migration.check import check_documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from typing import Optional

from libcommon.queue import JobDocument
from libcommon.queue.jobs import JobDocument
from libcommon.simple_cache import CachedResponseDocument
from mongoengine.connection import get_db

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2023 The HuggingFace Authors.

from libcommon.constants import QUEUE_COLLECTION_JOBS, QUEUE_MONGOENGINE_ALIAS
from libcommon.queue import JobDocument
from libcommon.queue.jobs import JobDocument
from libcommon.resources import MongoResource
from libcommon.utils import get_datetime
from mongoengine.connection import get_db
Expand Down
2 changes: 1 addition & 1 deletion jobs/mongodb_migration/tests/test_deletion_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
QUEUE_MONGOENGINE_ALIAS,
)
from libcommon.dtos import Status
from libcommon.queue import JobDocument
from libcommon.queue.jobs import JobDocument
from libcommon.resources import MongoResource
from libcommon.utils import get_datetime
from mongoengine.connection import get_db
Expand Down
2 changes: 1 addition & 1 deletion libs/libapi/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path

from libcommon.config import CacheConfig, QueueConfig
from libcommon.queue import _clean_queue_database
from libcommon.queue.utils import _clean_queue_database
from libcommon.resources import CacheMongoResource, QueueMongoResource
from libcommon.simple_cache import _clean_cache_database
from pytest import MonkeyPatch, TempPathFactory, fixture
Expand Down
2 changes: 1 addition & 1 deletion libs/libcommon/src/libcommon/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from libcommon.dtos import JobInfo, JobResult, Priority
from libcommon.processing_graph import ProcessingGraph, ProcessingStep, ProcessingStepDoesNotExist, processing_graph
from libcommon.prometheus import StepProfiler
from libcommon.queue import Queue
from libcommon.queue.jobs import Queue
from libcommon.simple_cache import (
CachedArtifactNotFoundError,
delete_dataset_responses,
Expand Down
2 changes: 1 addition & 1 deletion libs/libcommon/src/libcommon/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from psutil import disk_usage

from libcommon.constants import LONG_DURATION_PROMETHEUS_HISTOGRAM_BUCKETS
from libcommon.queue import JobTotalMetricDocument, WorkerSizeJobsCountDocument
from libcommon.queue.metrics import JobTotalMetricDocument, WorkerSizeJobsCountDocument
from libcommon.simple_cache import CacheTotalMetricDocument
from libcommon.storage import StrPath

Expand Down
3 changes: 3 additions & 0 deletions libs/libcommon/src/libcommon/queue/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 The HuggingFace Authors.

Loading

0 comments on commit d19ec87

Please sign in to comment.