1- from enum import Enum
21import json
32import logging
43import time
5- import warnings
64from collections import namedtuple
75from datetime import datetime , timezone
86from pathlib import Path
1816from labelbox .orm .db_object import DbObject , Updateable , Deletable
1917from labelbox .orm .model import Entity , Field , Relationship
2018from labelbox .pagination import PaginatedCollection
21- from labelbox .schema .resource_tag import ResourceTag
2219from labelbox .schema .media_type import MediaType
20+ from labelbox .schema .queue_mode import QueueMode
21+ from labelbox .schema .resource_tag import ResourceTag
2322
2423if 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
0 commit comments