class Operation
A class representing the status of a long-running operation, inheriting from Entity to track operation metadata.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/operations/operation.py
6 - 14
simple
Purpose
This class provides a structured way to monitor and access information about long-running operations in the Office 365 API. It extends the Entity base class and exposes operation metadata, particularly the creation timestamp. This is typically used when working with asynchronous operations that may take significant time to complete, allowing clients to track when operations were initiated.
Source Code
class Operation(Entity):
"""The status of a long-running operation."""
@property
def created_datetime(self):
"""
The start time of the operation.
"""
return self.properties("createdDateTime", datetime.min)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
__init__: Inherits constructor from Entity base class. The exact parameters depend on the Entity parent class implementation, but typically includes properties dictionary or keyword arguments that populate the entity's properties.
Return Value
Instantiation returns an Operation object that represents a long-running operation. The created_datetime property returns a datetime object representing when the operation started, defaulting to datetime.min if the createdDateTime property is not set.
Class Interface
Methods
@property created_datetime(self) -> datetime
property
Purpose: Retrieves the start time of the long-running operation from the entity's properties
Returns: A datetime object representing when the operation was created. Returns datetime.min if the createdDateTime property is not available in the entity's properties.
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
properties |
method (inherited from Entity) | Inherited method from Entity base class that retrieves property values by key name with optional default values | instance |
Dependencies
datetimeoffice365.entity
Required Imports
from datetime import datetime
from office365.entity import Entity
Usage Example
from datetime import datetime
from office365.entity import Entity
from operation import Operation
# Assuming Entity provides a way to set properties
operation = Operation()
# The operation would typically be created by an Office 365 API call
# that returns operation status
# Access the creation time of the operation
creation_time = operation.created_datetime
print(f"Operation started at: {creation_time}")
# Check if operation was actually created (not default value)
if creation_time != datetime.min:
print("Operation has a valid creation timestamp")
else:
print("Operation creation time not set")
Best Practices
- Always check if created_datetime returns datetime.min, which indicates the property was not set in the underlying data
- This class is designed to be instantiated by Office 365 API responses rather than directly by user code
- The Operation object relies on the Entity base class's properties() method to retrieve data, so ensure the parent class is properly initialized
- Use this class as part of polling or callback mechanisms to track long-running operations
- Consider the timezone of the returned datetime value, as Office 365 APIs may return UTC times
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class OnenoteOperation 67.7% similar
-
class CommsOperation 65.3% similar
-
class InviteParticipantsOperation 60.3% similar
-
class SPLargeOperation 59.4% similar
-
class DataPolicyOperation 59.3% similar