Skip to content

Commit 1822f99

Browse files
author
Richard Sun
committed
[QQC-486] Introduce ability to specify queue mode during project creation
1 parent 20fe6b7 commit 1822f99

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

labelbox/schema/project.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from enum import Enum
21
import json
32
import logging
43
import time
5-
import warnings
64
from collections import namedtuple
75
from datetime import datetime, timezone
86
from pathlib import Path
@@ -18,8 +16,9 @@
1816
from labelbox.orm.db_object import DbObject, Updateable, Deletable
1917
from labelbox.orm.model import Entity, Field, Relationship
2018
from labelbox.pagination import PaginatedCollection
21-
from labelbox.schema.resource_tag import ResourceTag
2219
from labelbox.schema.media_type import MediaType
20+
from labelbox.schema.queue_mode import QueueMode
21+
from labelbox.schema.resource_tag import ResourceTag
2322

2423
if TYPE_CHECKING:
2524
from labelbox import BulkImportRequest
@@ -50,6 +49,7 @@ class Project(DbObject, Updateable, Deletable):
5049
created_at (datetime)
5150
setup_complete (datetime)
5251
last_activity_time (datetime)
52+
queue_mode (string)
5353
auto_audit_number_of_labels (int)
5454
auto_audit_percentage (float)
5555
@@ -70,6 +70,7 @@ class Project(DbObject, Updateable, Deletable):
7070
created_at = Field.DateTime("created_at")
7171
setup_complete = Field.DateTime("setup_complete")
7272
last_activity_time = Field.DateTime("last_activity_time")
73+
queue_mode = Field.Enum(QueueMode, "queue_mode")
7374
auto_audit_number_of_labels = Field.Int("auto_audit_number_of_labels")
7475
auto_audit_percentage = Field.Float("auto_audit_percentage")
7576
# Bind data_type and allowedMediaTYpe using the GraphQL type MediaType
@@ -88,10 +89,6 @@ class Project(DbObject, Updateable, Deletable):
8889
benchmarks = Relationship.ToMany("Benchmark", False)
8990
ontology = Relationship.ToOne("Ontology", True)
9091

91-
class QueueMode(Enum):
92-
Batch = "Batch"
93-
Dataset = "Dataset"
94-
9592
def update(self, **kwargs):
9693
""" Updates this project with the specified attributes
9794
@@ -109,7 +106,7 @@ def update(self, **kwargs):
109106
Attempting to switch between benchmark and consensus modes is an invalid operation and will result
110107
in an error.
111108
"""
112-
mode: Optional[Project.QueueMode] = kwargs.pop("queue_mode", None)
109+
mode: Optional[QueueMode] = kwargs.pop("queue_mode", None)
113110
if mode:
114111
self._update_queue_mode(mode)
115112

@@ -573,7 +570,7 @@ def create_batch(self, name: str, data_rows: List[str], priority: int = 5):
573570
"""
574571

575572
# @TODO: make this automatic?
576-
if self.queue_mode() != Project.QueueMode.Batch:
573+
if self.queue_mode != QueueMode.Batch:
577574
raise ValueError("Project must be in batch mode")
578575

579576
dr_ids = []
@@ -619,14 +616,28 @@ def create_batch(self, name: str, data_rows: List[str], priority: int = 5):
619616
return Entity.Batch(self.client, self.uid, res)
620617

621618
def _update_queue_mode(self,
622-
mode: "Project.QueueMode") -> "Project.QueueMode":
619+
mode: "QueueMode") -> "QueueMode":
620+
621+
"""
622+
Updates the queueing mode of this project.
623+
624+
This method is deprecated. Going forward, projects must go through a
625+
migration to have the queue mode changed. Users should specify the
626+
queue mode for a project during creation if a non-default mode is desired.
627+
628+
Args:
629+
mode: the specified queue mode
623630
624-
if self.queue_mode() == mode:
631+
Returns: the updated queueing mode of this project
632+
633+
"""
634+
635+
if self.queue_mode == mode:
625636
return mode
626637

627-
if mode == Project.QueueMode.Batch:
638+
if mode == QueueMode.Batch:
628639
status = "ENABLED"
629-
elif mode == Project.QueueMode.Dataset:
640+
elif mode == QueueMode.Dataset:
630641
status = "DISABLED"
631642
else:
632643
raise ValueError(
@@ -648,8 +659,17 @@ def _update_queue_mode(self,
648659

649660
return mode
650661

651-
def queue_mode(self) -> "Project.QueueMode":
652-
"""Provides the status of if queue mode is enabled in the project."""
662+
def get_queue_mode(self) -> "QueueMode":
663+
"""
664+
Provides the status of if queue mode is enabled in the project.
665+
666+
This method is deprecated and will be removed in a future version. To obtain
667+
the queue mode of a project, simply refer to the queue_mode attribute of a
668+
Project.
669+
670+
Returns: the QueueMode for this project
671+
672+
"""
653673

654674
query_str = """query %s($projectId: ID!) {
655675
project(where: {id: $projectId}) {
@@ -662,9 +682,9 @@ def queue_mode(self) -> "Project.QueueMode":
662682
query_str, {'projectId': self.uid})["project"]["tagSetStatus"]
663683

664684
if status == "ENABLED":
665-
return Project.QueueMode.Batch
685+
return QueueMode.Batch
666686
elif status == "DISABLED":
667-
return Project.QueueMode.Dataset
687+
return QueueMode.Dataset
668688
else:
669689
raise ValueError("Status not known")
670690

labelbox/schema/queue_mode.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from enum import Enum
2+
3+
4+
class QueueMode(str, Enum):
5+
Batch = "CATALOG"
6+
Dataset = "DATA_SET"

tests/integration/test_project.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
from labelbox import Project, LabelingFrontend, Dataset
88
from labelbox.exceptions import InvalidQueryError
99
from labelbox.schema.media_type import MediaType
10+
from labelbox.schema.queue_mode import QueueMode
1011

1112

1213
def test_project(client, rand_gen):
1314
before = list(client.get_projects())
1415
for o in before:
1516
assert isinstance(o, Project)
1617

17-
data = {"name": rand_gen(str), "description": rand_gen(str)}
18+
data = {"name": rand_gen(str), "description": rand_gen(str), "queue_mode": QueueMode.Dataset}
1819
project = client.create_project(**data)
1920
assert project.name == data["name"]
2021
assert project.description == data["description"]
@@ -198,10 +199,8 @@ def test_queued_data_row_export(configured_project):
198199

199200

200201
def test_queue_mode(configured_project: Project):
201-
assert configured_project.queue_mode(
202-
) == configured_project.QueueMode.Dataset
203-
configured_project.update(queue_mode=configured_project.QueueMode.Batch)
204-
assert configured_project.queue_mode() == configured_project.QueueMode.Batch
202+
# ensures default queue mode is dataset
203+
assert configured_project.queue_mode == QueueMode.Dataset
205204

206205

207206
def test_batches(configured_project: Project, dataset: Dataset, image_url):

0 commit comments

Comments
 (0)