velocity-python 0.0.158__py3-none-any.whl → 0.0.160__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.
Potentially problematic release.
This version of velocity-python might be problematic. Click here for more details.
- velocity/__init__.py +1 -1
- velocity/aws/handlers/context.py +87 -3
- {velocity_python-0.0.158.dist-info → velocity_python-0.0.160.dist-info}/METADATA +1 -1
- {velocity_python-0.0.158.dist-info → velocity_python-0.0.160.dist-info}/RECORD +7 -7
- {velocity_python-0.0.158.dist-info → velocity_python-0.0.160.dist-info}/WHEEL +0 -0
- {velocity_python-0.0.158.dist-info → velocity_python-0.0.160.dist-info}/licenses/LICENSE +0 -0
- {velocity_python-0.0.158.dist-info → velocity_python-0.0.160.dist-info}/top_level.txt +0 -0
velocity/__init__.py
CHANGED
velocity/aws/handlers/context.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import os
|
|
2
3
|
import boto3
|
|
3
4
|
import uuid
|
|
@@ -24,6 +25,8 @@ class Context:
|
|
|
24
25
|
self.__aws_event = aws_event
|
|
25
26
|
self.__aws_context = aws_context
|
|
26
27
|
self.__log = log
|
|
28
|
+
self._job_record_cache = {}
|
|
29
|
+
self._job_cancelled_flag = False
|
|
27
30
|
|
|
28
31
|
def postdata(self, keys=-1, default=None):
|
|
29
32
|
if keys == -1:
|
|
@@ -87,9 +90,9 @@ class Context:
|
|
|
87
90
|
if self.postdata("job_id"):
|
|
88
91
|
# Sanitize data before storing in database
|
|
89
92
|
sanitized_data = self._sanitize_job_data(data)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
93
|
+
job_id = self.postdata("job_id")
|
|
94
|
+
tx.table("aws_job_activity").update(sanitized_data, {"job_id": job_id})
|
|
95
|
+
self._job_record_cache.pop(job_id, None)
|
|
93
96
|
tx.commit()
|
|
94
97
|
|
|
95
98
|
def create_job(self, tx, job_data=None):
|
|
@@ -98,6 +101,9 @@ class Context:
|
|
|
98
101
|
return
|
|
99
102
|
sanitized_data = self._sanitize_job_data(job_data)
|
|
100
103
|
tx.table("aws_job_activity").insert(sanitized_data)
|
|
104
|
+
job_id = sanitized_data.get("job_id")
|
|
105
|
+
if job_id:
|
|
106
|
+
self._job_record_cache.pop(job_id, None)
|
|
101
107
|
tx.commit()
|
|
102
108
|
|
|
103
109
|
def _sanitize_job_data(self, data):
|
|
@@ -183,6 +189,84 @@ class Context:
|
|
|
183
189
|
|
|
184
190
|
return sanitized
|
|
185
191
|
|
|
192
|
+
def _get_job_record(self, tx, job_id=None, refresh=False):
|
|
193
|
+
job_id = job_id or self.postdata("job_id")
|
|
194
|
+
if not job_id:
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
if refresh or job_id not in self._job_record_cache:
|
|
198
|
+
record = tx.table("aws_job_activity").find({"job_id": job_id})
|
|
199
|
+
if record is not None:
|
|
200
|
+
self._job_record_cache[job_id] = record
|
|
201
|
+
elif job_id in self._job_record_cache:
|
|
202
|
+
del self._job_record_cache[job_id]
|
|
203
|
+
|
|
204
|
+
return self._job_record_cache.get(job_id)
|
|
205
|
+
|
|
206
|
+
def is_job_cancel_requested(self, tx, force_refresh=False):
|
|
207
|
+
job = self._get_job_record(tx, refresh=force_refresh)
|
|
208
|
+
if not job:
|
|
209
|
+
return False
|
|
210
|
+
|
|
211
|
+
status = (job.get("status") or "").lower()
|
|
212
|
+
if status in {"cancelrequested", "cancelled"}:
|
|
213
|
+
return True
|
|
214
|
+
|
|
215
|
+
message_raw = job.get("message")
|
|
216
|
+
if not message_raw:
|
|
217
|
+
return False
|
|
218
|
+
|
|
219
|
+
if isinstance(message_raw, dict):
|
|
220
|
+
message = message_raw
|
|
221
|
+
else:
|
|
222
|
+
try:
|
|
223
|
+
message = json.loads(message_raw)
|
|
224
|
+
except (TypeError, ValueError, json.JSONDecodeError):
|
|
225
|
+
return False
|
|
226
|
+
|
|
227
|
+
return bool(message.get("cancel_requested") or message.get("cancelled"))
|
|
228
|
+
|
|
229
|
+
def mark_job_cancelled(self, tx, detail=None, requested_by=None):
|
|
230
|
+
job_id = self.postdata("job_id")
|
|
231
|
+
if not job_id:
|
|
232
|
+
return
|
|
233
|
+
|
|
234
|
+
job = self._get_job_record(tx, refresh=True) or {}
|
|
235
|
+
message_raw = job.get("message")
|
|
236
|
+
if isinstance(message_raw, dict):
|
|
237
|
+
message = dict(message_raw)
|
|
238
|
+
else:
|
|
239
|
+
try:
|
|
240
|
+
message = json.loads(message_raw) if message_raw else {}
|
|
241
|
+
except (TypeError, ValueError, json.JSONDecodeError):
|
|
242
|
+
message = {}
|
|
243
|
+
|
|
244
|
+
message.update(
|
|
245
|
+
{
|
|
246
|
+
"detail": detail or "Job cancelled",
|
|
247
|
+
"cancelled": True,
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
tx.table("aws_job_activity").update(
|
|
252
|
+
{
|
|
253
|
+
"status": "Cancelled",
|
|
254
|
+
"message": to_json(message),
|
|
255
|
+
"handler_complete_timestamp": datetime.now(),
|
|
256
|
+
"sys_modified": datetime.now(),
|
|
257
|
+
"sys_modified_by": requested_by
|
|
258
|
+
or self.session().get("email_address")
|
|
259
|
+
or "system",
|
|
260
|
+
},
|
|
261
|
+
{"job_id": job_id},
|
|
262
|
+
)
|
|
263
|
+
tx.commit()
|
|
264
|
+
self._job_record_cache.pop(job_id, None)
|
|
265
|
+
self._job_cancelled_flag = True
|
|
266
|
+
|
|
267
|
+
def was_job_cancelled(self):
|
|
268
|
+
return self._job_cancelled_flag
|
|
269
|
+
|
|
186
270
|
def enqueue(self, action, payload={}, user=None, suppress_job_activity=False):
|
|
187
271
|
"""
|
|
188
272
|
Enqueue jobs to SQS with independent job activity tracking.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
velocity/__init__.py,sha256=
|
|
1
|
+
velocity/__init__.py,sha256=t8R519NPfB30baxwfHpQFR_kMmzXUu0_bglALFT14QM,147
|
|
2
2
|
velocity/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
velocity/app/invoices.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
velocity/app/orders.py,sha256=C7ewngMpO8nD3ul_82o4FhZBdRkWvJtnuEbEJUKDCno,6151
|
|
@@ -12,7 +12,7 @@ velocity/aws/__init__.py,sha256=0nEsX68Q4I7Z7ybECJnNWsC8QhWOijn4NpaFgyzyfXA,685
|
|
|
12
12
|
velocity/aws/amplify.py,sha256=VgSgon0XxboIozz0tKyUohgLIigelhe4W7EH8kwbnLg,15330
|
|
13
13
|
velocity/aws/handlers/__init__.py,sha256=4-NKj8dBzjYEdIlNdfm_Ip5mI0oOGcpjjBcMwU42yhQ,227
|
|
14
14
|
velocity/aws/handlers/base_handler.py,sha256=bapdzWss5lXesoLPsVwJo9hQMZLdz7XOubo3sK70xC8,7960
|
|
15
|
-
velocity/aws/handlers/context.py,sha256=
|
|
15
|
+
velocity/aws/handlers/context.py,sha256=yL1oA8y6q0b1Vg3KUB0XWJ0hqnToScZuBXEHpWif8V0,11259
|
|
16
16
|
velocity/aws/handlers/exceptions.py,sha256=i4wcB8ZSWUHglX2xnesDlWLsU9AMYU72cHCWRBDmjQ8,361
|
|
17
17
|
velocity/aws/handlers/lambda_handler.py,sha256=0wa_CHyJOaI5RsHqB0Ae83-B-SwlKR0qkGUlc7jitQI,4427
|
|
18
18
|
velocity/aws/handlers/response.py,sha256=s2Kw7yv5zAir1mEmfv6yBVIvRcRQ__xyryf1SrvtiRc,9317
|
|
@@ -122,8 +122,8 @@ velocity/misc/tests/test_merge.py,sha256=Vm5_jY5cVczw0hZF-3TYzmxFw81heJOJB-dvhCg
|
|
|
122
122
|
velocity/misc/tests/test_oconv.py,sha256=fy4DwWGn_v486r2d_3ACpuBD-K1oOngNq1HJCGH7X-M,4694
|
|
123
123
|
velocity/misc/tests/test_original_error.py,sha256=iWSd18tckOA54LoPQOGV5j9LAz2W-3_ZOwmyZ8-4YQc,1742
|
|
124
124
|
velocity/misc/tests/test_timer.py,sha256=l9nrF84kHaFofvQYKInJmfoqC01wBhsUB18lVBgXCoo,2758
|
|
125
|
-
velocity_python-0.0.
|
|
126
|
-
velocity_python-0.0.
|
|
127
|
-
velocity_python-0.0.
|
|
128
|
-
velocity_python-0.0.
|
|
129
|
-
velocity_python-0.0.
|
|
125
|
+
velocity_python-0.0.160.dist-info/licenses/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
|
|
126
|
+
velocity_python-0.0.160.dist-info/METADATA,sha256=Gq-LK_UyNdBt4epmv7xgrwbcsSPIRa8XsiyB_BoSQyo,34266
|
|
127
|
+
velocity_python-0.0.160.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
128
|
+
velocity_python-0.0.160.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
|
|
129
|
+
velocity_python-0.0.160.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|