cobweb-launcher 1.2.52__py3-none-any.whl → 1.2.53__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 cobweb-launcher might be problematic. Click here for more details.

cobweb/db/redis_db.py CHANGED
@@ -16,6 +16,14 @@ class RedisDB:
16
16
  return redis.StrictRedis(connection_pool=self.pool)
17
17
  # self._client = redis.Redis(connection_pool=pool)
18
18
 
19
+ def get(self, name):
20
+ with self.get_connection() as client:
21
+ return client.get(name)
22
+
23
+ def incrby(self, name, value):
24
+ with self.get_connection() as client:
25
+ client.incrby(name, value)
26
+
19
27
  def setnx(self, name, value=""):
20
28
  with self.get_connection() as client:
21
29
  client.setnx(name, value)
@@ -51,6 +51,8 @@ class Launcher(threading.Thread):
51
51
  "_delete",
52
52
  ]
53
53
 
54
+ __WORKER_THREAD__ = {}
55
+
54
56
  def __init__(self, task, project, custom_setting=None, **kwargs):
55
57
  super().__init__()
56
58
  self.task = task
@@ -179,9 +181,22 @@ class Launcher(threading.Thread):
179
181
 
180
182
  def _execute(self):
181
183
  for func_name in self.__LAUNCHER_FUNC__:
182
- threading.Thread(name=func_name, target=getattr(self, func_name)).start()
184
+ worker_thread = threading.Thread(name=func_name, target=getattr(self, func_name))
185
+ self.__WORKER_THREAD__[func_name] = worker_thread
186
+ worker_thread.start()
183
187
  time.sleep(1)
184
188
 
189
+ def _monitor(self):
190
+ while True:
191
+ for func_name, worker_thread in self.__WORKER_THREAD__.items():
192
+ if not worker_thread.is_alive():
193
+ logger.info(f"{func_name} thread is dead. Restarting...")
194
+ target = getattr(self, func_name)
195
+ worker_thread = threading.Thread(name=func_name, target=target)
196
+ self.__WORKER_THREAD__[func_name] = worker_thread
197
+ worker_thread.start()
198
+ time.sleep(5)
199
+
185
200
  def run(self):
186
201
  threading.Thread(target=self._execute_heartbeat).start()
187
202
 
@@ -210,6 +225,8 @@ class Launcher(threading.Thread):
210
225
  wait_seconds=self._upload_queue_wait_seconds
211
226
  ).start()
212
227
 
228
+ threading.Thread(target=self._monitor).start()
229
+
213
230
  self._execute()
214
231
  self._polling()
215
232
 
@@ -40,11 +40,11 @@ class LauncherPro(Launcher):
40
40
  if not self._task_model and not self._db.exists(key):
41
41
  self._db.setex(key, 86400 * 30, int(count))
42
42
  else:
43
- self._db._client.incrby(key, count)
43
+ self._db.incrby(key, count)
44
44
 
45
45
  def _get_seed(self) -> Seed:
46
46
  if self._speed_control:
47
- spider_speed = self._db._client.get(self._speed_control_key)
47
+ spider_speed = self._db.get(self._speed_control_key)
48
48
  if int(spider_speed or 0) > self._spider_max_count:
49
49
  expire_time = self._db.ttl(self._speed_control_key)
50
50
  if expire_time == -1:
@@ -55,7 +55,7 @@ class LauncherPro(Launcher):
55
55
  return None
56
56
  seed = self.__LAUNCHER_QUEUE__["todo"].pop()
57
57
  if self._speed_control and seed and not self._db.lock(self._speed_control_key, t=self._time_window):
58
- self._db._client.incrby(self._speed_control_key, 1)
58
+ self._db.incrby(self._speed_control_key, 1)
59
59
  return seed
60
60
 
61
61
  @check_pause
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cobweb-launcher
3
- Version: 1.2.52
3
+ Version: 1.2.53
4
4
  Summary: spider_hole
5
5
  Home-page: https://github.com/Juannie-PP/cobweb
6
6
  Author: Juannie-PP
@@ -17,14 +17,14 @@ cobweb/crawlers/crawler.py,sha256=pePDGroD6JJAht5QTU51L7MkFIY4ob9TKpznZ2wUmsw,89
17
17
  cobweb/crawlers/file_crawler.py,sha256=2Sjbdgxzqd41WykKUQE3QQlGai3T8k-pmHNmPlTchjQ,4454
18
18
  cobweb/db/__init__.py,sha256=uZwSkd105EAwYo95oZQXAfofUKHVIAZZIPpNMy-hm2Q,56
19
19
  cobweb/db/api_db.py,sha256=bDc5dJQxq4z04h70KUTHd0OqUOEY7Cm3wcNJZtTvJIM,3015
20
- cobweb/db/redis_db.py,sha256=mEWTBWSBXOhf3qxU9fdXYrhNJ44O8pS9tvqEAvZNhoI,5156
20
+ cobweb/db/redis_db.py,sha256=DG-8l5DKRTs2ln1g9SM6gBMkmmjAcCM7RHL84eIuH60,5385
21
21
  cobweb/exceptions/__init__.py,sha256=E9SHnJBbhD7fOgPFMswqyOf8SKRDrI_i25L0bSpohvk,32
22
22
  cobweb/exceptions/oss_db_exception.py,sha256=iP_AImjNHT3-Iv49zCFQ3rdLnlvuHa3h2BXApgrOYpA,636
23
23
  cobweb/launchers/__init__.py,sha256=qMuVlQcjErVK67HyKFZEsXf_rfZD5ODjx1QucSCKMOM,114
24
- cobweb/launchers/launcher.py,sha256=_qC3EnD_QxQRP_RBNHHJ8HLfn_0FED1jUF_lyas5Hss,7081
24
+ cobweb/launchers/launcher.py,sha256=c2Jo9ppzJwzDONXP3hPaN-_DW58JeMe1HUBGKr9YTag,7797
25
25
  cobweb/launchers/launcher_air.py,sha256=KAk_M8F3029cXYe7m4nn3Nzyi89lbxJ2cqZjqW8iZ0E,2832
26
26
  cobweb/launchers/launcher_api.py,sha256=7K7Kl3dk7Ung9iRBwhiMrALEJywcR66ie5RIkLQEM-Y,7909
27
- cobweb/launchers/launcher_pro.py,sha256=QMumHUTi6IudO5mw9SnwlmP8k_BJ50cpNjYjoQv-_YY,7936
27
+ cobweb/launchers/launcher_pro.py,sha256=QCmOzlIDvdfdfZVK7rQN6PYou9Vedepie1aqqeHlI2w,7912
28
28
  cobweb/pipelines/__init__.py,sha256=zSUsGtx6smbs2iXBXvYynReKSgky-3gjqaAtKVnA_OU,105
29
29
  cobweb/pipelines/pipeline.py,sha256=4TJLX0sUHRxYndF5A4Vs5btUGI-wigkOcFvhTW1hLXI,2009
30
30
  cobweb/pipelines/pipeline_console.py,sha256=NEh-4zhuVAQOqwXLsqeb-rcNZ9_KXFUpL3otUTL5qBs,754
@@ -37,8 +37,8 @@ cobweb/utils/bloom.py,sha256=vng-YbKgh9HbtpAWYf_nkUSbfVTOj40aqUUejRYlsCU,1752
37
37
  cobweb/utils/dotting.py,sha256=mVICaa26R-dQ4JGmPK-kkR6QjX38QiRewXZnGb2DCIc,1784
38
38
  cobweb/utils/oss.py,sha256=gyt8-UB07tVphZLQXMOf-JTJwU-mWq8KZkOXKkAf3uk,3513
39
39
  cobweb/utils/tools.py,sha256=5JEaaAwYoV9Sdla2UBIJn6faUBuXmxUMagm9ck6FVqs,1253
40
- cobweb_launcher-1.2.52.dist-info/LICENSE,sha256=z1rxSIGOyzcSb3orZxFPxzx-0C1vTocmswqBNxpKfEk,1063
41
- cobweb_launcher-1.2.52.dist-info/METADATA,sha256=lUniniJ1G9qDV9zA4XtI2p5bZPwDkMI6fKPSGnWjb_g,6510
42
- cobweb_launcher-1.2.52.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
43
- cobweb_launcher-1.2.52.dist-info/top_level.txt,sha256=4GETBGNsKqiCUezmT-mJn7tjhcDlu7nLIV5gGgHBW4I,7
44
- cobweb_launcher-1.2.52.dist-info/RECORD,,
40
+ cobweb_launcher-1.2.53.dist-info/LICENSE,sha256=z1rxSIGOyzcSb3orZxFPxzx-0C1vTocmswqBNxpKfEk,1063
41
+ cobweb_launcher-1.2.53.dist-info/METADATA,sha256=AwxLfnqtHeoXUJAY7X8yLzZ1lLZr4XxAViYOH6ExClQ,6510
42
+ cobweb_launcher-1.2.53.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
43
+ cobweb_launcher-1.2.53.dist-info/top_level.txt,sha256=4GETBGNsKqiCUezmT-mJn7tjhcDlu7nLIV5gGgHBW4I,7
44
+ cobweb_launcher-1.2.53.dist-info/RECORD,,