corva-worker-python 2.0.0__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.
- corva_worker_python-2.0.0.dist-info/METADATA +30 -0
- corva_worker_python-2.0.0.dist-info/RECORD +63 -0
- corva_worker_python-2.0.0.dist-info/WHEEL +5 -0
- corva_worker_python-2.0.0.dist-info/top_level.txt +1 -0
- worker/__init__.py +5 -0
- worker/app/__init__.py +291 -0
- worker/app/modules/__init__.py +265 -0
- worker/app/modules/activity_module.py +141 -0
- worker/app/modules/connection_module.py +21 -0
- worker/app/modules/depth_activity_module.py +21 -0
- worker/app/modules/scheduler.py +44 -0
- worker/app/modules/time_activity_module.py +21 -0
- worker/app/modules/trigger.py +43 -0
- worker/constants.py +51 -0
- worker/data/__init__.py +0 -0
- worker/data/activity/__init__.py +132 -0
- worker/data/activity/activity_grouping.py +242 -0
- worker/data/alert.py +89 -0
- worker/data/api.py +155 -0
- worker/data/enums.py +141 -0
- worker/data/json_encoder.py +18 -0
- worker/data/math.py +104 -0
- worker/data/operations.py +477 -0
- worker/data/serialization.py +110 -0
- worker/data/task_handler.py +82 -0
- worker/data/two_way_dict.py +17 -0
- worker/data/unit_conversions.py +5 -0
- worker/data/wits.py +323 -0
- worker/event/__init__.py +53 -0
- worker/event/event_handler.py +90 -0
- worker/event/scheduled.py +64 -0
- worker/event/stream.py +48 -0
- worker/exceptions.py +26 -0
- worker/mixins/__init__.py +0 -0
- worker/mixins/logging.py +119 -0
- worker/mixins/rollbar.py +87 -0
- worker/partial_rerun_merge/__init__.py +0 -0
- worker/partial_rerun_merge/merge.py +500 -0
- worker/partial_rerun_merge/models.py +91 -0
- worker/partial_rerun_merge/progress.py +241 -0
- worker/state/__init__.py +96 -0
- worker/state/mixins.py +111 -0
- worker/state/state.py +46 -0
- worker/test/__init__.py +3 -0
- worker/test/lambda_function_test_run.py +196 -0
- worker/test/local_testing/__init__.py +0 -0
- worker/test/local_testing/to_local_transfer.py +360 -0
- worker/test/utils.py +51 -0
- worker/wellbore/__init__.py +0 -0
- worker/wellbore/factory.py +496 -0
- worker/wellbore/measured_depth_finder.py +12 -0
- worker/wellbore/model/__init__.py +0 -0
- worker/wellbore/model/ann.py +103 -0
- worker/wellbore/model/annulus.py +113 -0
- worker/wellbore/model/drillstring.py +196 -0
- worker/wellbore/model/drillstring_components.py +439 -0
- worker/wellbore/model/element.py +102 -0
- worker/wellbore/model/enums.py +92 -0
- worker/wellbore/model/hole.py +297 -0
- worker/wellbore/model/hole_section.py +51 -0
- worker/wellbore/model/riser.py +22 -0
- worker/wellbore/sections_mixin.py +64 -0
- worker/wellbore/wellbore.py +289 -0
worker/exceptions.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class CorvaException(Exception):
|
|
2
|
+
pass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Misconfigured(Exception):
|
|
6
|
+
pass
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class APIError(CorvaException):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NotFound(CorvaException):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Forbidden(CorvaException):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MissingConfigError(Exception):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class EventFormatError(Exception):
|
|
26
|
+
pass
|
|
File without changes
|
worker/mixins/logging.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from worker.data.operations import is_number
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class LoggingMixin(object):
|
|
8
|
+
LOGGING_LEVELS = [
|
|
9
|
+
"all", # Show all messages
|
|
10
|
+
"debug", # Show debug, info, warnings, errors, and fatal messages (Equal to all)
|
|
11
|
+
"info", # Show info, warnings, errors, and fatal messages
|
|
12
|
+
"warn", # Show warnings, errors, and fatal messages
|
|
13
|
+
"error", # Show errors and fatal messages
|
|
14
|
+
"fatal", # Show only fatal messages
|
|
15
|
+
"off", # No messages
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
def __init__(self, *args, **kwargs):
|
|
19
|
+
self.logging_level = os.getenv("LOGGING_LEVEL", "info").lower()
|
|
20
|
+
self.logging_asset_id = os.getenv("LOGGING_ASSET_ID", 0)
|
|
21
|
+
|
|
22
|
+
if self.logging_level not in self.LOGGING_LEVELS:
|
|
23
|
+
self.logging_level = "off"
|
|
24
|
+
|
|
25
|
+
if is_number(self.logging_asset_id):
|
|
26
|
+
self.logging_asset_id = int(self.logging_asset_id)
|
|
27
|
+
|
|
28
|
+
super().__init__(*args, **kwargs)
|
|
29
|
+
|
|
30
|
+
def all(self, asset_id, text):
|
|
31
|
+
self.call("all", asset_id, text)
|
|
32
|
+
|
|
33
|
+
def debug(self, asset_id, text):
|
|
34
|
+
self.call("debug", asset_id, text)
|
|
35
|
+
|
|
36
|
+
def info(self, asset_id, text):
|
|
37
|
+
self.call("info", asset_id, text)
|
|
38
|
+
|
|
39
|
+
def warn(self, asset_id, text):
|
|
40
|
+
self.call("warn", asset_id, text)
|
|
41
|
+
|
|
42
|
+
def error(self, asset_id, text):
|
|
43
|
+
self.call("error", asset_id, text)
|
|
44
|
+
|
|
45
|
+
def fatal(self, asset_id, text):
|
|
46
|
+
self.call("fatal", asset_id, text)
|
|
47
|
+
|
|
48
|
+
def off(self, asset_id, text):
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
def call(self, method, asset_id, text):
|
|
52
|
+
if method == "off":
|
|
53
|
+
return
|
|
54
|
+
|
|
55
|
+
method_check = str(method) in self.LOGGING_LEVELS[self.LOGGING_LEVELS.index(self.logging_level) :]
|
|
56
|
+
if not method_check:
|
|
57
|
+
return
|
|
58
|
+
|
|
59
|
+
asset_id_check = (asset_id == self.logging_asset_id) or (self.logging_asset_id == "all")
|
|
60
|
+
if not asset_id_check:
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
self.log(asset_id, method, text)
|
|
64
|
+
|
|
65
|
+
@staticmethod
|
|
66
|
+
def log(asset_id, method="LOG", text=""):
|
|
67
|
+
if not method:
|
|
68
|
+
method = "LOG"
|
|
69
|
+
|
|
70
|
+
utc_time = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")
|
|
71
|
+
print(f"{utc_time} | {method.upper()} | asset_id_{asset_id} | {text}")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class Logger:
|
|
75
|
+
logger = None
|
|
76
|
+
asset_id = None
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def set_asset_id(cls, asset_id):
|
|
80
|
+
cls.asset_id = asset_id
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def get_logger(cls):
|
|
84
|
+
if cls.logger is None:
|
|
85
|
+
cls.logger = LoggingMixin()
|
|
86
|
+
|
|
87
|
+
return cls.logger
|
|
88
|
+
|
|
89
|
+
@classmethod
|
|
90
|
+
def all(cls, text):
|
|
91
|
+
cls.get_logger().call("all", cls.asset_id, text)
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def debug(cls, text):
|
|
95
|
+
cls.get_logger().call("debug", cls.asset_id, text)
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def info(cls, text):
|
|
99
|
+
cls.get_logger().call("info", cls.asset_id, text)
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def warn(cls, text):
|
|
103
|
+
cls.get_logger().call("warn", cls.asset_id, text)
|
|
104
|
+
|
|
105
|
+
@classmethod
|
|
106
|
+
def error(cls, text):
|
|
107
|
+
cls.get_logger().call("error", cls.asset_id, text)
|
|
108
|
+
|
|
109
|
+
@classmethod
|
|
110
|
+
def fatal(cls, text):
|
|
111
|
+
cls.get_logger().call("fatal", cls.asset_id, text)
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def off(cls, asset_id, text):
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
@classmethod
|
|
118
|
+
def log(cls, text):
|
|
119
|
+
cls.get_logger().log(cls.asset_id, "LOG", text)
|
worker/mixins/rollbar.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import reprlib
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class RollbarMixin(object):
|
|
6
|
+
def __init__(self, *args, **kwargs):
|
|
7
|
+
self.rollbar = kwargs.pop("rollbar", None)
|
|
8
|
+
super().__init__(*args, **kwargs)
|
|
9
|
+
|
|
10
|
+
def is_rollbar(self) -> bool:
|
|
11
|
+
"""
|
|
12
|
+
To check if rollbar is available or not
|
|
13
|
+
:return: if rollbar is available
|
|
14
|
+
"""
|
|
15
|
+
return self.rollbar and self.rollbar.SETTINGS.get("enabled")
|
|
16
|
+
|
|
17
|
+
def track_message(self, message: str, level: str):
|
|
18
|
+
"""
|
|
19
|
+
To send a message to rollbar
|
|
20
|
+
:param message:
|
|
21
|
+
:param level: any of the following levels:
|
|
22
|
+
['critical', 'error', 'warning', 'info', 'debug', 'ignored']
|
|
23
|
+
:return:
|
|
24
|
+
"""
|
|
25
|
+
# Levels:
|
|
26
|
+
if not self.is_rollbar():
|
|
27
|
+
print(f"{level} - {message}")
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
level = level.lower()
|
|
31
|
+
|
|
32
|
+
self.rollbar.report_message(message, level)
|
|
33
|
+
|
|
34
|
+
def track_error(self, message: str = None):
|
|
35
|
+
if not self.is_rollbar():
|
|
36
|
+
raise
|
|
37
|
+
|
|
38
|
+
self.rollbar.report_exc_info(extra_data=message, level="error")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def payload_handler(payload: dict, **kw) -> dict: # kw is currently unused
|
|
42
|
+
"""
|
|
43
|
+
This is a rollbar payload handler which will be called on every payload being sent to rollbar
|
|
44
|
+
This handler has to be added to rollbar instance after init
|
|
45
|
+
|
|
46
|
+
Rollbar already applies a shortening transform to the payload using reprlib and custom sizes defined in rollbar init
|
|
47
|
+
But it somehow seems to miss nested lists which is a usual format in our apps using corva-worker-python
|
|
48
|
+
This payload handler applies the same reprlib to the lists missed by rollbar's shortener
|
|
49
|
+
|
|
50
|
+
Use like -> rollbar.events.add_payload_handler(payload_handler)
|
|
51
|
+
To pause trimming set REDUCED_ROLLBAR_PAYLOAD to False or false in env variables
|
|
52
|
+
|
|
53
|
+
:param payload: Payload automatically captured based on exc, args and locals
|
|
54
|
+
:param kw:
|
|
55
|
+
:return: Trimmed payload
|
|
56
|
+
"""
|
|
57
|
+
reduced_rollbar_payload_flag = os.getenv("REDUCED_ROLLBAR_PAYLOAD", "true").lower()
|
|
58
|
+
|
|
59
|
+
# If REDUCED_ROLLBAR_PAYLOAD is set to False or false in env variables, trimming will be paused
|
|
60
|
+
if reduced_rollbar_payload_flag == "false":
|
|
61
|
+
return payload
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
payload_frames = payload["data"]["body"]["trace"].pop("frames", [])
|
|
65
|
+
except KeyError:
|
|
66
|
+
return payload
|
|
67
|
+
|
|
68
|
+
# All the locals are nested inside frames.
|
|
69
|
+
# Smartly payload reduce size
|
|
70
|
+
for frame in payload_frames:
|
|
71
|
+
local_vars = frame.get("locals", {})
|
|
72
|
+
|
|
73
|
+
# Instantiating repr from reprlib. Using this to trim nested datasets
|
|
74
|
+
_repr = reprlib.Repr()
|
|
75
|
+
|
|
76
|
+
# Setting custom max sizes for dict and list
|
|
77
|
+
setattr(_repr, "maxdict", 10)
|
|
78
|
+
setattr(_repr, "maxlist", 2)
|
|
79
|
+
|
|
80
|
+
for key, value in local_vars.items():
|
|
81
|
+
# Applying trim to only dicts and lists.
|
|
82
|
+
# If there are other nested data types, they will be trimmed based on default repr limits
|
|
83
|
+
if isinstance(value, (dict, list)):
|
|
84
|
+
local_vars[key] = _repr.repr(value)
|
|
85
|
+
|
|
86
|
+
payload["data"]["body"]["trace"]["frames"] = payload_frames
|
|
87
|
+
return payload
|
|
File without changes
|