1+ from __future__ import annotations
2+
13import time
4+ from collections .abc import Callable
25from datetime import datetime
36from typing import Optional
47
8+ from typing_extensions import Self
9+
510from office365 .entity import Entity
611from office365 .runtime .types .odata_property import odata
12+ from office365 .teams .operations .async_status import TeamsAsyncOperationStatus
713from office365 .teams .operations .error import OperationError
814from office365 .teams .operations .type import TeamsAsyncOperationType
915
@@ -23,30 +29,30 @@ class TeamsAsyncOperation(Entity):
2329
2430 def poll_for_status (
2531 self ,
26- status_type = " succeeded" ,
27- max_polling_count = 5 ,
28- polling_interval_secs = 15 ,
29- success_callback = None ,
30- failure_callback = None ,
31- ):
32+ status_type : TeamsAsyncOperationStatus = TeamsAsyncOperationStatus . succeeded ,
33+ max_polling_count : int = 5 ,
34+ polling_interval_secs : int = 15 ,
35+ success_callback : Callable [[ TeamsAsyncOperation ], None ] | None = None ,
36+ failure_callback : Callable [[ TeamsAsyncOperation ], None ] | None = None ,
37+ ) -> Self :
3238 """Poll to check for completion of an async Teams create call
3339
3440 Args:
3541 polling_interval_secs (int):
3642 max_polling_count (int):
37- status_type (str ): The status of a teamsAsyncOperation
38- success_callback ((TeamsAsyncOperation)-> None): A callback to call if the request executes successfully.
39- failure_callback ((TeamsAsyncOperation)-> None): A callback to call if the request fails to execute
43+ status_type (TeamsAsyncOperationStatus ): The status to wait for
44+ success_callback ((TeamsAsyncOperation)-> None): Called on success with the operation
45+ failure_callback ((TeamsAsyncOperation)-> None): Called on timeout
4046 """
4147
4248 def _poll_for_status (polling_number : int ) -> None :
4349 if polling_number > max_polling_count :
4450 if callable (failure_callback ):
4551 failure_callback (self )
4652 else :
47- raise TypeError ("The maximum polling count has been reached" )
53+ raise TimeoutError ("The maximum polling count has been reached" )
4854
49- def _verify_status (return_type ):
55+ def _verify_status (return_type : TeamsAsyncOperation ):
5056 if return_type .status != status_type :
5157 time .sleep (polling_interval_secs )
5258 _poll_for_status (polling_number + 1 )
@@ -66,31 +72,31 @@ def attempts_count(self) -> Optional[int]:
6672
6773 @odata (name = "createdDateTime" )
6874 @property
69- def created_date_time (self ) -> Optional [ datetime ] :
75+ def created_date_time (self ) -> datetime :
7076 """Date and time when the operation was created."""
71- return self .properties .get ("createdDateTime" , None )
77+ return self .properties .get ("createdDateTime" , datetime . min )
7278
7379 @property
74- def error (self ) -> Optional [ OperationError ] :
80+ def error (self ) -> OperationError :
7581 """Error information if the operation failed."""
76- return self .properties .get ("error" , None )
82+ return self .properties .get ("error" , OperationError () )
7783
7884 @odata (name = "lastActionDateTime" )
7985 @property
80- def last_action_date_time (self ) -> Optional [ datetime ] :
86+ def last_action_date_time (self ) -> datetime :
8187 """Date and time when the operation was last updated."""
82- return self .properties .get ("lastActionDateTime" , None )
88+ return self .properties .get ("lastActionDateTime" , datetime . min )
8389
8490 @odata (name = "operationType" )
8591 @property
86- def operation_type (self ) -> Optional [ TeamsAsyncOperationType ] :
92+ def operation_type (self ) -> TeamsAsyncOperationType :
8793 """The type of the operation."""
88- return self .properties .get ("operationType" , None )
94+ return self .properties .get ("operationType" , TeamsAsyncOperationType . unknown )
8995
9096 @property
91- def status (self ) -> Optional [ str ] :
97+ def status (self ) -> TeamsAsyncOperationStatus :
9298 """Operation status."""
93- return self .properties .get ("status" , None )
99+ return self .properties .get ("status" , TeamsAsyncOperationStatus . invalid )
94100
95101 @property
96102 def target_resource_id (self ) -> Optional [str ]:
0 commit comments