cobweb-launcher 1.2.51__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 +48 -18
- cobweb/launchers/launcher.py +18 -1
- cobweb/launchers/launcher_pro.py +3 -3
- {cobweb_launcher-1.2.51.dist-info → cobweb_launcher-1.2.53.dist-info}/METADATA +1 -1
- {cobweb_launcher-1.2.51.dist-info → cobweb_launcher-1.2.53.dist-info}/RECORD +8 -8
- {cobweb_launcher-1.2.51.dist-info → cobweb_launcher-1.2.53.dist-info}/LICENSE +0 -0
- {cobweb_launcher-1.2.51.dist-info → cobweb_launcher-1.2.53.dist-info}/WHEEL +0 -0
- {cobweb_launcher-1.2.51.dist-info → cobweb_launcher-1.2.53.dist-info}/top_level.txt +0 -0
cobweb/db/redis_db.py
CHANGED
|
@@ -6,60 +6,90 @@ class RedisDB:
|
|
|
6
6
|
|
|
7
7
|
def __init__(self, **kwargs):
|
|
8
8
|
redis_config = kwargs or setting.REDIS_CONFIG
|
|
9
|
-
pool = redis.ConnectionPool(**redis_config)
|
|
10
|
-
self.
|
|
9
|
+
# pool = redis.ConnectionPool(**redis_config)
|
|
10
|
+
self.pool = redis.ConnectionPool(
|
|
11
|
+
max_connections=25,
|
|
12
|
+
**redis_config
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def get_connection(self):
|
|
16
|
+
return redis.StrictRedis(connection_pool=self.pool)
|
|
17
|
+
# self._client = redis.Redis(connection_pool=pool)
|
|
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)
|
|
11
26
|
|
|
12
27
|
def setnx(self, name, value=""):
|
|
13
|
-
|
|
28
|
+
with self.get_connection() as client:
|
|
29
|
+
client.setnx(name, value)
|
|
14
30
|
|
|
15
31
|
def setex(self, name, t, value=""):
|
|
16
|
-
|
|
32
|
+
with self.get_connection() as client:
|
|
33
|
+
client.setex(name, t, value)
|
|
17
34
|
|
|
18
35
|
def expire(self, name, t, nx: bool = False, xx: bool = False, gt: bool = False, lt: bool = False):
|
|
19
|
-
|
|
36
|
+
with self.get_connection() as client:
|
|
37
|
+
client.expire(name, t, nx, xx, gt, lt)
|
|
20
38
|
|
|
21
39
|
def ttl(self, name):
|
|
22
|
-
|
|
40
|
+
with self.get_connection() as client:
|
|
41
|
+
return client.ttl(name)
|
|
23
42
|
|
|
24
43
|
def delete(self, name):
|
|
25
|
-
|
|
44
|
+
with self.get_connection() as client:
|
|
45
|
+
return client.delete(name)
|
|
26
46
|
|
|
27
47
|
def exists(self, *name) -> bool:
|
|
28
|
-
|
|
48
|
+
with self.get_connection() as client:
|
|
49
|
+
return client.exists(*name)
|
|
29
50
|
|
|
30
51
|
def sadd(self, name, value):
|
|
31
|
-
|
|
52
|
+
with self.get_connection() as client:
|
|
53
|
+
return client.sadd(name, value)
|
|
32
54
|
|
|
33
55
|
def zcard(self, name) -> bool:
|
|
34
|
-
|
|
56
|
+
with self.get_connection() as client:
|
|
57
|
+
return client.zcard(name)
|
|
35
58
|
|
|
36
59
|
def zadd(self, name, item: dict, **kwargs):
|
|
37
|
-
|
|
60
|
+
with self.get_connection() as client:
|
|
61
|
+
return client.zadd(name, item, **kwargs)
|
|
38
62
|
|
|
39
63
|
def zrem(self, name, *value):
|
|
40
|
-
|
|
64
|
+
with self.get_connection() as client:
|
|
65
|
+
return client.zrem(name, *value)
|
|
41
66
|
|
|
42
67
|
def zcount(self, name, _min, _max):
|
|
43
|
-
|
|
68
|
+
with self.get_connection() as client:
|
|
69
|
+
return client.zcount(name, _min, _max)
|
|
44
70
|
|
|
45
71
|
# def zrangebyscore(self, name, _min, _max, start, num, withscores: bool = False, *args):
|
|
46
|
-
#
|
|
72
|
+
# with self.get_connection() as client:
|
|
73
|
+
# return client.zrangebyscore(name, _min, _max, start, num, withscores, *args)
|
|
47
74
|
|
|
48
75
|
def lua(self, script: str, keys: list = None, args: list = None):
|
|
49
76
|
keys = keys or []
|
|
50
77
|
args = args or []
|
|
51
78
|
keys_count = len(keys)
|
|
52
|
-
|
|
79
|
+
with self.get_connection() as client:
|
|
80
|
+
return client.eval(script, keys_count, *keys, *args)
|
|
53
81
|
|
|
54
82
|
def lua_sha(self, sha1: str, keys: list = None, args: list = None):
|
|
55
83
|
keys = keys or []
|
|
56
84
|
args = args or []
|
|
57
85
|
keys_count = len(keys)
|
|
58
|
-
|
|
86
|
+
with self.get_connection() as client:
|
|
87
|
+
return client.evalsha(sha1, keys_count, *keys, *args)
|
|
59
88
|
|
|
60
89
|
def execute_lua(self, lua_script: str, keys: list, *args):
|
|
61
|
-
|
|
62
|
-
|
|
90
|
+
with self.get_connection() as client:
|
|
91
|
+
execute = client.register_script(lua_script)
|
|
92
|
+
return execute(keys=keys, args=args)
|
|
63
93
|
|
|
64
94
|
def lock(self, key, t=15) -> bool:
|
|
65
95
|
lua_script = """
|
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,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))
|
|
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
|
|
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=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=
|
|
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.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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|