Microsoft Azure Storage Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Storage task assignments for automated data processing and reporting on task execution. Storage tasks enable automated data transformation, processing, and management operations on storage account data.
Create and manage storage task assignments that define automated processing operations on storage data.
class StorageTaskAssignmentsOperations:
def create(
self,
resource_group_name: str,
account_name: str,
storage_task_assignment_name: str,
parameters: StorageTaskAssignment
) -> StorageTaskAssignment:
"""
Creates a new storage task assignment.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- storage_task_assignment_name: Name of the storage task assignment
- parameters: Storage task assignment configuration
Returns:
Created StorageTaskAssignment
"""
def get(
self,
resource_group_name: str,
account_name: str,
storage_task_assignment_name: str
) -> StorageTaskAssignment:
"""
Gets properties of a specified storage task assignment.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- storage_task_assignment_name: Name of the storage task assignment
Returns:
StorageTaskAssignment with current configuration
"""
def delete(
self,
resource_group_name: str,
account_name: str,
storage_task_assignment_name: str
) -> None:
"""
Deletes a storage task assignment.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- storage_task_assignment_name: Name of the storage task assignment
"""
def list(
self,
resource_group_name: str,
account_name: str,
maxpagesize: Optional[int] = None
) -> ItemPaged[StorageTaskAssignment]:
"""
Lists all storage task assignments in a storage account.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- maxpagesize: Maximum number of results per page
Returns:
Paginated list of StorageTaskAssignment objects
"""
def update(
self,
resource_group_name: str,
account_name: str,
storage_task_assignment_name: str,
parameters: StorageTaskAssignmentUpdateParameters
) -> StorageTaskAssignment:
"""
Updates properties of a storage task assignment.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- storage_task_assignment_name: Name of the storage task assignment
- parameters: Updated storage task assignment properties
Returns:
Updated StorageTaskAssignment
"""Usage example:
from azure.mgmt.storage.models import (
StorageTaskAssignment, StorageTaskAssignmentProperties,
ExecutionTrigger, TriggerParameters, ExecutionTarget
)
# Create a storage task assignment for data processing
execution_trigger = ExecutionTrigger(
type_=TriggerType.ON_SCHEDULE,
parameters=TriggerParameters(
start_on="2024-01-01T00:00:00Z",
interval=24, # Run daily
interval_unit="hours"
)
)
execution_target = ExecutionTarget(
prefix="data-processing/",
exclude_prefix=["temp/", "logs/"]
)
task_assignment = StorageTaskAssignment(
properties=StorageTaskAssignmentProperties(
task_id="/subscriptions/sub-id/resourceGroups/tasks-rg/providers/Microsoft.StorageActions/storageTasks/data-processor",
enabled=True,
description="Daily data processing and transformation task",
execution_context=StorageTaskAssignmentExecutionContext(
trigger=execution_trigger,
target=execution_target
),
report=StorageTaskAssignmentReport(
prefix="reports/task-reports/"
)
)
)
created_assignment = client.storage_task_assignments.create(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
storage_task_assignment_name="daily-data-processing",
parameters=task_assignment
)
print(f"Created task assignment: {created_assignment.name}")
# Create a cleanup task assignment
cleanup_trigger = ExecutionTrigger(
type_=TriggerType.ON_SCHEDULE,
parameters=TriggerParameters(
start_on="2024-01-01T02:00:00Z",
interval=168, # Run weekly (7 days * 24 hours)
interval_unit="hours"
)
)
cleanup_target = ExecutionTarget(
prefix="temp/",
exclude_prefix=["temp/important/"]
)
cleanup_assignment = StorageTaskAssignment(
properties=StorageTaskAssignmentProperties(
task_id="/subscriptions/sub-id/resourceGroups/tasks-rg/providers/Microsoft.StorageActions/storageTasks/cleanup-task",
enabled=True,
description="Weekly cleanup of temporary files",
execution_context=StorageTaskAssignmentExecutionContext(
trigger=cleanup_trigger,
target=cleanup_target
),
report=StorageTaskAssignmentReport(
prefix="reports/cleanup-reports/"
)
)
)
client.storage_task_assignments.create(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
storage_task_assignment_name="weekly-cleanup",
parameters=cleanup_assignment
)
# List all task assignments
assignments = list(client.storage_task_assignments.list(
resource_group_name="my-resource-group",
account_name="mystorageaccount123"
))
print(f"Total task assignments: {len(assignments)}")
for assignment in assignments:
print(f"Assignment: {assignment.name}")
print(f" Enabled: {assignment.properties.enabled}")
print(f" Description: {assignment.properties.description}")
print(f" Task ID: {assignment.properties.task_id}")
# Update task assignment
from azure.mgmt.storage.models import (
StorageTaskAssignmentUpdateParameters, StorageTaskAssignmentUpdateProperties,
StorageTaskAssignmentUpdateExecutionContext, ExecutionTriggerUpdate,
TriggerParametersUpdate
)
updated_trigger = ExecutionTriggerUpdate(
type_=TriggerType.ON_SCHEDULE,
parameters=TriggerParametersUpdate(
interval=12, # Change to every 12 hours
interval_unit="hours"
)
)
update_params = StorageTaskAssignmentUpdateParameters(
properties=StorageTaskAssignmentUpdateProperties(
enabled=True,
description="Updated: Semi-daily data processing task",
execution_context=StorageTaskAssignmentUpdateExecutionContext(
trigger=updated_trigger
)
)
)
updated_assignment = client.storage_task_assignments.update(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
storage_task_assignment_name="daily-data-processing",
parameters=update_params
)
print(f"Updated task assignment: {updated_assignment.name}")Monitor and retrieve reports on storage task assignment execution.
class StorageTaskAssignmentsInstancesReportOperations:
def list(
self,
resource_group_name: str,
account_name: str,
storage_task_assignment_name: str,
maxpagesize: Optional[int] = None,
filter: Optional[str] = None
) -> ItemPaged[StorageTaskReportInstance]:
"""
Lists execution instances of a storage task assignment.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- storage_task_assignment_name: Name of the storage task assignment
- maxpagesize: Maximum number of results per page
- filter: OData filter expression
Returns:
Paginated list of StorageTaskReportInstance objects
"""
class StorageTaskAssignmentInstancesReportOperations:
def list(
self,
resource_group_name: str,
account_name: str,
storage_task_assignment_name: str,
maxpagesize: Optional[int] = None,
filter: Optional[str] = None
) -> ItemPaged[StorageTaskReportInstance]:
"""
Lists task assignment instance reports.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- storage_task_assignment_name: Name of the storage task assignment
- maxpagesize: Maximum number of results per page
- filter: OData filter expression
Returns:
Paginated list of StorageTaskReportInstance objects
"""Usage example:
# List execution reports for a task assignment
execution_reports = list(client.storage_task_assignments_instances_report.list(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
storage_task_assignment_name="daily-data-processing",
maxpagesize=50
))
print(f"Found {len(execution_reports)} execution reports")
for report in execution_reports:
print(f"Execution ID: {report.properties.task_assignment_id}")
print(f" Start Time: {report.properties.start_time}")
print(f" Finish Time: {report.properties.finish_time}")
print(f" Status: {report.properties.run_status_enum}")
print(f" Run Result: {report.properties.run_result}")
if hasattr(report.properties, 'summary') and report.properties.summary:
summary = report.properties.summary
print(f" Objects Processed: {summary.objects_operated_on_count}")
print(f" Objects Failed: {summary.objects_failed_count}")
print(f" Objects Succeeded: {summary.objects_succeeded_count}")
print(f" Total Bytes Processed: {summary.total_objects_size_in_bytes}")
print()
# Filter reports by date range
from datetime import datetime, timedelta
last_week = (datetime.utcnow() - timedelta(days=7)).isoformat() + "Z"
filter_expression = f"properties/startTime ge '{last_week}'"
recent_reports = list(client.storage_task_assignment_instances_report.list(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
storage_task_assignment_name="daily-data-processing",
filter=filter_expression
))
print(f"Reports from last week: {len(recent_reports)}")
# Get reports for all task assignments
all_assignments = list(client.storage_task_assignments.list(
resource_group_name="my-resource-group",
account_name="mystorageaccount123"
))
for assignment in all_assignments:
reports = list(client.storage_task_assignments_instances_report.list(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
storage_task_assignment_name=assignment.name,
maxpagesize=10 # Get last 10 reports
))
print(f"Task: {assignment.name} - {len(reports)} recent reports")
# Calculate success rate
if reports:
successful = len([r for r in reports if r.properties.run_result == RunResult.SUCCEEDED])
success_rate = (successful / len(reports)) * 100
print(f" Success Rate: {success_rate:.1f}%")class StorageTaskAssignment:
"""Storage task assignment resource."""
id: str
name: str
type_: str
properties: StorageTaskAssignmentProperties
class StorageTaskAssignmentProperties:
"""Properties of storage task assignment."""
task_id: str
enabled: bool
description: str
execution_context: StorageTaskAssignmentExecutionContext
report: StorageTaskAssignmentReport
provisioning_state: ProvisioningState
class StorageTaskAssignmentExecutionContext:
"""Execution context for storage task assignment."""
trigger: ExecutionTrigger
target: ExecutionTarget
class ExecutionTrigger:
"""Trigger configuration for task execution."""
type_: TriggerType
parameters: TriggerParameters
class TriggerParameters:
"""Parameters for execution trigger."""
start_on: str
interval: int
interval_unit: str
end_on: str
class ExecutionTarget:
"""Target configuration for task execution."""
prefix: str
exclude_prefix: List[str]
class StorageTaskAssignmentReport:
"""Report configuration for task assignment."""
prefix: str
class StorageTaskReportInstance:
"""Individual task execution report."""
id: str
name: str
type_: str
properties: StorageTaskReportProperties
class StorageTaskReportProperties:
"""Properties of task execution report."""
task_assignment_id: str
storage_account_id: str
start_time: str
finish_time: str
object_target_count: str
objects_operated_on_count: str
objects_succeeded_count: str
objects_failed_count: str
run_status_enum: RunStatusEnum
run_result: RunResult
summary_report_path: str
task_id: str
task_version: str
class StorageTaskReportSummary:
"""Summary of task execution results."""
objects_count: str
objects_operated_on_count: str
objects_succeeded_count: str
objects_failed_count: str
total_objects_size_in_bytes: str
class StorageTaskAssignmentUpdateParameters:
"""Parameters for updating storage task assignment."""
properties: StorageTaskAssignmentUpdateProperties
class StorageTaskAssignmentUpdateProperties:
"""Updated properties for storage task assignment."""
enabled: bool
description: str
execution_context: StorageTaskAssignmentUpdateExecutionContext
report: StorageTaskAssignmentUpdateReport
class TriggerType(str, Enum):
"""Types of execution triggers."""
ON_SCHEDULE = "OnSchedule"
RUN_ONCE = "RunOnce"
class RunStatusEnum(str, Enum):
"""Status of task execution."""
IN_PROGRESS = "InProgress"
COMPLETED = "Completed"
FAILED = "Failed"
class RunResult(str, Enum):
"""Result of task execution."""
SUCCEEDED = "Succeeded"
FAILED = "Failed"Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-storage