lacuscore 1.14.0__py3-none-any.whl → 1.14.2__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.
lacuscore/lacuscore.py CHANGED
@@ -269,6 +269,7 @@ class LacusCore():
269
269
  p = self.redis.pipeline()
270
270
  p.set(f'lacus:query_hash:{hash_query}', perma_uuid, nx=True, ex=recapture_interval)
271
271
  p.hset(f'lacus:capture_settings:{perma_uuid}', mapping=to_enqueue.redis_dump())
272
+ p.expire(f'lacus:capture_settings:{perma_uuid}', self.max_capture_time * 2)
272
273
  p.zadd('lacus:to_capture', {perma_uuid: priority if priority is not None else 0})
273
274
  try:
274
275
  p.execute()
@@ -330,15 +331,29 @@ class LacusCore():
330
331
  """
331
332
  if self.redis.zscore('lacus:to_capture', uuid) is not None:
332
333
  return CaptureStatus.QUEUED
333
- elif self.redis.zscore('lacus:ongoing', uuid) is not None:
334
+ if self.redis.zscore('lacus:ongoing', uuid) is not None:
334
335
  return CaptureStatus.ONGOING
335
- elif self.redis.exists(f'lacus:capture_settings:{uuid}'):
336
- # we might have popped the UUID out of lacus:to_capture
337
- # but not pused it in lacus:ongoing yet
338
- return CaptureStatus.QUEUED
339
- elif self.redis.exists(f'lacus:capture_results_hash:{uuid}'):
336
+ if self.redis.exists(f'lacus:capture_settings:{uuid}'):
337
+ # we might have a race condition between when the UUID is popped out of lacus:to_capture,
338
+ # and pushed in lacus:ongoing.
339
+ # if that's the case, we wait for a sec and check lacus:ongoing again
340
+ # If it's still not in ongoing, the UUID is broken and can be consdered unknown.
341
+ # This key is removed anyway once the capture is done.
342
+ max_checks = 10
343
+ for i in range(max_checks):
344
+ time.sleep(.1)
345
+ if self.redis.zscore('lacus:to_capture', uuid) is not None:
346
+ # Could be re-added in that queue if the capture failed, but will be retried
347
+ return CaptureStatus.QUEUED
348
+ if self.redis.zscore('lacus:ongoing', uuid) is not None:
349
+ # The capture is actually ongoing now
350
+ return CaptureStatus.ONGOING
351
+ # The UUID is still no anywhere to be found, it's broken.
352
+ self.redis.delete(f'lacus:capture_settings:{uuid}')
353
+ return CaptureStatus.UNKNOWN
354
+ if self.redis.exists(f'lacus:capture_results_hash:{uuid}'):
340
355
  return CaptureStatus.DONE
341
- elif self.redis.exists(f'lacus:capture_results:{uuid}'):
356
+ if self.redis.exists(f'lacus:capture_results:{uuid}'):
342
357
  # TODO: remove in 1.8.* - old format used last in 1.6, and kept no more than 10H in redis
343
358
  return CaptureStatus.DONE
344
359
  return CaptureStatus.UNKNOWN
@@ -622,6 +637,11 @@ class LacusCore():
622
637
  # NOTE: in this block, we absolutely have to make sure the UUID is removed
623
638
  # from the lacus:ongoing sorted set (it is definitely not ongoing anymore)
624
639
  # and optionally re-added to lacus:to_capture if re want to retry it
640
+ #
641
+ # In order to have a consistent capture status, the capture UUID must either be in
642
+ # lacus:ongoing (while ongoing), in lacus:to_capture (on retry), or the result stored (on success).
643
+ # If the capture fails to be stored in valkey, we must also remove the capture settings
644
+ # so it is not dangling there.
625
645
 
626
646
  if to_capture.document:
627
647
  os.unlink(tmp_f.name)
@@ -654,7 +674,11 @@ class LacusCore():
654
674
  retry_redis_error -= 1
655
675
  await asyncio.sleep(random.randint(5, 10))
656
676
  else:
657
- self.redis.zrem('lacus:ongoing', uuid)
677
+ # Unrecoverable redis error, remove the capture settings
678
+ p = self.redis.pipeline()
679
+ p.delete(f'lacus:capture_settings:{uuid}')
680
+ p.zrem('lacus:ongoing', uuid)
681
+ p.execute()
658
682
  stats_pipeline.zincrby(f'stats:{today}:errors', 1, 'Redis Connection')
659
683
  logger.critical('Unable to connect to redis and to push the result of the capture.')
660
684
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lacuscore
3
- Version: 1.14.0
3
+ Version: 1.14.2
4
4
  Summary: Core of Lacus, usable as a module
5
5
  License: BSD-3-Clause
6
6
  Author: Raphaël Vinot
@@ -26,9 +26,9 @@ Requires-Dist: async-timeout (>=5.0.1) ; python_version < "3.11"
26
26
  Requires-Dist: defang (>=0.5.3)
27
27
  Requires-Dist: dnspython (>=2.7.0)
28
28
  Requires-Dist: eval-type-backport (>=0.2.2) ; python_version < "3.10"
29
- Requires-Dist: playwrightcapture[recaptcha] (>=1.29.0)
30
- Requires-Dist: pydantic (>=2.11.3)
31
- Requires-Dist: redis[hiredis] (>=5.2.1)
29
+ Requires-Dist: playwrightcapture[recaptcha] (>=1.29.3)
30
+ Requires-Dist: pydantic (>=2.11.4)
31
+ Requires-Dist: redis[hiredis] (>=5.3.0,<6.0.0)
32
32
  Requires-Dist: requests (>=2.32.3)
33
33
  Requires-Dist: typing-extensions (>=4.12.2,<5.0.0) ; python_version < "3.12"
34
34
  Requires-Dist: ua-parser[regex] (>=1.0.1)
@@ -1,10 +1,10 @@
1
1
  lacuscore/__init__.py,sha256=aLBshQPT9IBDKn5qWrX9A_exqtLFPyLsQiPWdfpAFjA,537
2
2
  lacuscore/helpers.py,sha256=d1rMHEA9A9NwfKksa2JvhLu-egaCBf1Vs2F7ALtAhmo,14264
3
3
  lacuscore/lacus_monitoring.py,sha256=r6IaYuh6sMq43eOWdZx0fU8p4PWVZlqSD6nr6yOaTUU,2713
4
- lacuscore/lacuscore.py,sha256=cENEza8A5NjW6aO9jImRYZTa5RKlMTHkRITAtMMYTnc,42941
4
+ lacuscore/lacuscore.py,sha256=zUkfSSn9_tFE9vnFo309obHJdvBBfhVjwe7IDL7csoU,44492
5
5
  lacuscore/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  lacuscore/task_logger.py,sha256=2wDotU6r6vn-aKO8nZNdxSuisSj11LlcxuvW60qPL0Y,1909
7
- lacuscore-1.14.0.dist-info/LICENSE,sha256=4C4hLYrIkUD96Ggk-y_Go1Qf7PBZrEm9PSeTGe2nd4s,1516
8
- lacuscore-1.14.0.dist-info/METADATA,sha256=-9LdOO7lsKp5UFHkS7JfC4Jg2O3cBjopjqnp1E6x1Zw,2647
9
- lacuscore-1.14.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
10
- lacuscore-1.14.0.dist-info/RECORD,,
7
+ lacuscore-1.14.2.dist-info/LICENSE,sha256=4C4hLYrIkUD96Ggk-y_Go1Qf7PBZrEm9PSeTGe2nd4s,1516
8
+ lacuscore-1.14.2.dist-info/METADATA,sha256=qkvp08WeFCrDYogV4NcoFFvGGlgvWZC3P6-RwkgtBJ0,2654
9
+ lacuscore-1.14.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
10
+ lacuscore-1.14.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.2
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any