cobweb-launcher 1.2.52__py3-none-any.whl → 1.2.54__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 +8 -0
- cobweb/launchers/launcher.py +21 -1
- cobweb/launchers/launcher_pro.py +3 -3
- {cobweb_launcher-1.2.52.dist-info → cobweb_launcher-1.2.54.dist-info}/METADATA +1 -1
- {cobweb_launcher-1.2.52.dist-info → cobweb_launcher-1.2.54.dist-info}/RECORD +8 -8
- {cobweb_launcher-1.2.52.dist-info → cobweb_launcher-1.2.54.dist-info}/LICENSE +0 -0
- {cobweb_launcher-1.2.52.dist-info → cobweb_launcher-1.2.54.dist-info}/WHEEL +0 -0
- {cobweb_launcher-1.2.52.dist-info → cobweb_launcher-1.2.54.dist-info}/top_level.txt +0 -0
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)
|
cobweb/launchers/launcher.py
CHANGED
|
@@ -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,25 @@ 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))
|
|
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
|
+
if not self.__WORKER_THREAD__:
|
|
192
|
+
time.sleep(15)
|
|
193
|
+
continue
|
|
194
|
+
for func_name, worker_thread in self.__WORKER_THREAD__.items():
|
|
195
|
+
if not worker_thread.is_alive():
|
|
196
|
+
logger.info(f"{func_name} thread is dead. Restarting...")
|
|
197
|
+
target = getattr(self, func_name)
|
|
198
|
+
worker_thread = threading.Thread(name=func_name, target=target)
|
|
199
|
+
self.__WORKER_THREAD__[func_name] = worker_thread
|
|
200
|
+
worker_thread.start()
|
|
201
|
+
time.sleep(5)
|
|
202
|
+
|
|
185
203
|
def run(self):
|
|
186
204
|
threading.Thread(target=self._execute_heartbeat).start()
|
|
187
205
|
|
|
@@ -210,6 +228,8 @@ class Launcher(threading.Thread):
|
|
|
210
228
|
wait_seconds=self._upload_queue_wait_seconds
|
|
211
229
|
).start()
|
|
212
230
|
|
|
231
|
+
threading.Thread(target=self._monitor).start()
|
|
232
|
+
|
|
213
233
|
self._execute()
|
|
214
234
|
self._polling()
|
|
215
235
|
|
cobweb/launchers/launcher_pro.py
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
58
|
+
self._db.incrby(self._speed_control_key, 1)
|
|
59
59
|
return seed
|
|
60
60
|
|
|
61
61
|
@check_pause
|
|
@@ -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=
|
|
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=
|
|
24
|
+
cobweb/launchers/launcher.py,sha256=y1a72sANV-oJVpy_BI7BwKy7fY4AnpHqJK3t6czoCts,7896
|
|
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=
|
|
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.
|
|
41
|
-
cobweb_launcher-1.2.
|
|
42
|
-
cobweb_launcher-1.2.
|
|
43
|
-
cobweb_launcher-1.2.
|
|
44
|
-
cobweb_launcher-1.2.
|
|
40
|
+
cobweb_launcher-1.2.54.dist-info/LICENSE,sha256=z1rxSIGOyzcSb3orZxFPxzx-0C1vTocmswqBNxpKfEk,1063
|
|
41
|
+
cobweb_launcher-1.2.54.dist-info/METADATA,sha256=n9jaFGNujOnCTREmaWA7yM66RKuj5VK1aAvQ_EJRqiU,6510
|
|
42
|
+
cobweb_launcher-1.2.54.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
|
|
43
|
+
cobweb_launcher-1.2.54.dist-info/top_level.txt,sha256=4GETBGNsKqiCUezmT-mJn7tjhcDlu7nLIV5gGgHBW4I,7
|
|
44
|
+
cobweb_launcher-1.2.54.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|