-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathOperationResult.py
More file actions
94 lines (79 loc) · 2.61 KB
/
Copy pathOperationResult.py
File metadata and controls
94 lines (79 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from typing import Optional, Dict, Any
from azure.functions._durable_functions import _serialize_custom_object
import json
class OperationResult:
"""OperationResult.
The result of an Entity operation.
"""
def __init__(self,
is_error: bool,
duration: int,
execution_start_time_ms: int,
result: Optional[str] = None):
"""Instantiate an OperationResult.
Parameters
----------
is_error: bool
Whether or not the operation resulted in an exception.
duration: int
How long the operation took, in milliseconds.
start_time: int
The start time of this operation's execution, in milliseconds,
since January 1st 1970 midnight in UTC.
result: Optional[str]
The operation result. Defaults to None.
"""
self._is_error: bool = is_error
self._duration: int = duration
self._execution_start_time_ms: int = execution_start_time_ms
self._result: Optional[str] = result
@property
def is_error(self) -> bool:
"""Determine if the operation resulted in an error.
Returns
-------
bool
True if the operation resulted in error. Otherwise False.
"""
return self._is_error
@property
def duration(self) -> int:
"""Get the duration of this operation.
Returns
-------
int:
The duration of this operation, in milliseconds
"""
return self._duration
@property
def execution_start_time_ms(self) -> int:
"""Get the start time of this operation.
Returns
-------
int:
The start time of this operation's execution, in milliseconds,
since January 1st 1970 midnight in UTC.
"""
return self._execution_start_time_ms
@property
def result(self) -> Any:
"""Get the operation's result.
Returns
-------
Any
The operation's result
"""
return self._result
def to_json(self) -> Dict[str, Any]:
"""Represent OperationResult as a JSON-serializable Dict.
Returns
-------
Dict[str, Any]
A JSON-serializable Dict of the OperationResult
"""
to_json: Dict[str, Any] = {}
to_json["isError"] = self.is_error
to_json["duration"] = self.duration
to_json["startTime"] = self.execution_start_time_ms
to_json["result"] = json.dumps(self.result, default=_serialize_custom_object)
return to_json