clerk-sdk 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clerk/decorator/task_decorator.py +42 -18
- {clerk_sdk-0.3.2.dist-info → clerk_sdk-0.3.4.dist-info}/METADATA +1 -1
- {clerk_sdk-0.3.2.dist-info → clerk_sdk-0.3.4.dist-info}/RECORD +6 -6
- {clerk_sdk-0.3.2.dist-info → clerk_sdk-0.3.4.dist-info}/WHEEL +0 -0
- {clerk_sdk-0.3.2.dist-info → clerk_sdk-0.3.4.dist-info}/licenses/LICENSE +0 -0
- {clerk_sdk-0.3.2.dist-info → clerk_sdk-0.3.4.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import os
|
|
2
1
|
import pickle
|
|
3
2
|
import traceback
|
|
4
3
|
from typing import Callable, Optional
|
|
@@ -17,8 +16,14 @@ def clerk_code():
|
|
|
17
16
|
def wrapper(payload: Optional[ClerkCodePayload] = None) -> ClerkCodePayload:
|
|
18
17
|
# 1. Load payload from file if not provided
|
|
19
18
|
use_pickle = False
|
|
19
|
+
output = None
|
|
20
|
+
error_occurred = False
|
|
21
|
+
error_info = None
|
|
20
22
|
if payload is None:
|
|
21
23
|
use_pickle = True
|
|
24
|
+
# Write a placeholder output file in case of early failure
|
|
25
|
+
with open(output_pkl, "wb") as f:
|
|
26
|
+
pickle.dump({"error": "Early failure"}, f)
|
|
22
27
|
try:
|
|
23
28
|
with open(input_pkl, "rb") as f:
|
|
24
29
|
raw_data = pickle.load(f)
|
|
@@ -28,34 +33,53 @@ def clerk_code():
|
|
|
28
33
|
else raw_data
|
|
29
34
|
)
|
|
30
35
|
except Exception as e:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
error_occurred = True
|
|
37
|
+
error_info = ApplicationException(
|
|
38
|
+
type_=str(type(e)),
|
|
39
|
+
message=f"Failed to load and parse input pickle: {e}",
|
|
40
|
+
traceback=traceback.format_exc(),
|
|
41
|
+
)
|
|
34
42
|
|
|
35
43
|
# 2. Execute function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
if not error_occurred:
|
|
45
|
+
try:
|
|
46
|
+
output = func(payload)
|
|
47
|
+
if not isinstance(output, ClerkCodePayload):
|
|
48
|
+
raise TypeError(
|
|
49
|
+
"Function must return a ClerkCodePayload instance."
|
|
50
|
+
)
|
|
51
|
+
except Exception as e:
|
|
52
|
+
error_occurred = True
|
|
53
|
+
error_info = ApplicationException(
|
|
54
|
+
type_=str(type(e)),
|
|
55
|
+
message=str(e),
|
|
56
|
+
traceback=traceback.format_exc(),
|
|
57
|
+
)
|
|
45
58
|
|
|
46
59
|
# 3. write to output.pkl
|
|
47
60
|
try:
|
|
48
61
|
if use_pickle:
|
|
49
62
|
with open(output_pkl, "wb") as f:
|
|
50
|
-
if
|
|
63
|
+
if error_occurred:
|
|
64
|
+
pickle.dump(error_info, f)
|
|
65
|
+
elif isinstance(output, Exception):
|
|
51
66
|
pickle.dump(output, f)
|
|
52
67
|
else:
|
|
53
68
|
pickle.dump(output.model_dump(mode="json"), f)
|
|
54
|
-
|
|
55
69
|
except Exception as e:
|
|
56
|
-
output
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
# If writing output.pkl fails, try to write a minimal error
|
|
71
|
+
try:
|
|
72
|
+
with open(output_pkl, "wb") as f:
|
|
73
|
+
pickle.dump(
|
|
74
|
+
ApplicationException(
|
|
75
|
+
type_=str(type(e)),
|
|
76
|
+
message=f"Failed to write output pickle: {str(e)}",
|
|
77
|
+
traceback=traceback.format_exc(),
|
|
78
|
+
),
|
|
79
|
+
f,
|
|
80
|
+
)
|
|
81
|
+
except Exception:
|
|
82
|
+
pass # Last resort: do nothing if even this fails
|
|
59
83
|
|
|
60
84
|
# 4. Raise if error or return result
|
|
61
85
|
if isinstance(output, Exception):
|
|
@@ -3,7 +3,7 @@ clerk/base.py,sha256=Ayb2zCQr8fqKZM_Qh3nVxVJOQkkYt-eD5VtpPXd1TLs,2669
|
|
|
3
3
|
clerk/client.py,sha256=6nWWWjGB7a6FNUWsZRM-IoBb_mshRi6g5KX8meMiJ2E,576
|
|
4
4
|
clerk/decorator/__init__.py,sha256=4VCGOFNq7pA7iJS410V_R9eWfjxP7mwxwa4thwaUTf8,39
|
|
5
5
|
clerk/decorator/models.py,sha256=JWFOJuUh3F40iOL0aoNgUC9GRHU3Fcq3GOjSXA7Gwng,394
|
|
6
|
-
clerk/decorator/task_decorator.py,sha256=
|
|
6
|
+
clerk/decorator/task_decorator.py,sha256=RarLfGR0uDtIBWlaPSIvGhIi2gmHPa4_825RBAL3DgI,3610
|
|
7
7
|
clerk/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
clerk/exceptions/exceptions.py,sha256=aIrmID62HoQo0pLErfX9NR2nopTyf53BpOu4gtqAy-A,1201
|
|
9
9
|
clerk/exceptions/remote_device.py,sha256=R0Vfmk8ejibEFeV29A8Vqst2YA6yxdqEX9lP5wWubgM,134
|
|
@@ -46,8 +46,8 @@ clerk/models/ui_operator.py,sha256=mKTJUFZgv7PeEt5oys28HVZxHOJsofmRQOcRpqj0dbU,2
|
|
|
46
46
|
clerk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
47
47
|
clerk/utils/logger.py,sha256=vHbp-lUK3W3c5fhyPsp05p9LGyDHj95v8XM_XQ_FlLc,3691
|
|
48
48
|
clerk/utils/save_artifact.py,sha256=94aYkYNVGcSUaSWZmdjiY6Oc-3yCKb2XWCZ56IAXQqk,1158
|
|
49
|
-
clerk_sdk-0.3.
|
|
50
|
-
clerk_sdk-0.3.
|
|
51
|
-
clerk_sdk-0.3.
|
|
52
|
-
clerk_sdk-0.3.
|
|
53
|
-
clerk_sdk-0.3.
|
|
49
|
+
clerk_sdk-0.3.4.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
|
|
50
|
+
clerk_sdk-0.3.4.dist-info/METADATA,sha256=o4_bSFkp3m__xIXnwkfZZlqMJvWvCGJvm27hO7LBbLw,3508
|
|
51
|
+
clerk_sdk-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
52
|
+
clerk_sdk-0.3.4.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
|
|
53
|
+
clerk_sdk-0.3.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|