2022-09-07 06:20:30 +00:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
import ujson
|
|
|
|
|
2022-09-07 06:20:30 +00:00
|
|
|
import db
|
|
|
|
import util
|
2022-09-13 21:17:46 +00:00
|
|
|
from processing import process
|
|
|
|
|
2022-09-14 17:32:32 +00:00
|
|
|
SOURCES = ["4ch", "irc", "dis"]
|
2022-09-07 06:20:30 +00:00
|
|
|
KEYPREFIX = "queue."
|
2022-09-14 17:32:32 +00:00
|
|
|
CHUNK_SIZE = 90000
|
2022-09-07 06:20:30 +00:00
|
|
|
ITER_DELAY = 0.5
|
|
|
|
|
2022-09-07 06:20:30 +00:00
|
|
|
|
2022-09-07 06:20:30 +00:00
|
|
|
class Ingest(object):
|
|
|
|
def __init__(self):
|
|
|
|
name = self.__class__.__name__
|
|
|
|
self.log = util.get_logger(name)
|
|
|
|
|
|
|
|
async def run(self):
|
2022-09-14 17:32:32 +00:00
|
|
|
# items = [{'no': 23567753, 'now': '09/12/22(Mon)20:10:29', 'name': 'Anonysmous', 'filename': '1644986767568', 'ext': '.webm', 'w': 1280, 'h': 720, 'tn_w': 125, 'tn_h': 70, 'tim': 1663027829301457, 'time': 1663027829, 'md5': 'zeElr1VR05XpZ2XuAPhmPA==', 'fsize': 3843621, 'resto': 23554700, 'type': 'msg', 'src': '4ch', 'net': 'gif', 'channel': '23554700'}]
|
|
|
|
# await process.spawn_processing_threads(items)
|
2022-09-07 06:20:30 +00:00
|
|
|
while True:
|
2022-09-13 21:17:46 +00:00
|
|
|
await self.get_chunk()
|
2022-09-07 06:20:30 +00:00
|
|
|
await asyncio.sleep(ITER_DELAY)
|
|
|
|
|
2022-09-13 21:17:46 +00:00
|
|
|
async def get_chunk(self):
|
2022-09-07 06:20:30 +00:00
|
|
|
items = []
|
|
|
|
for source in SOURCES:
|
|
|
|
key = f"{KEYPREFIX}{source}"
|
|
|
|
chunk = await db.ar.spop(key, CHUNK_SIZE)
|
|
|
|
if not chunk:
|
|
|
|
continue
|
2022-09-14 17:32:32 +00:00
|
|
|
# self.log.info(f"Got chunk: {chunk}")
|
2022-09-07 06:20:30 +00:00
|
|
|
for item in chunk:
|
|
|
|
item = ujson.loads(item)
|
2022-09-14 17:32:32 +00:00
|
|
|
# self.log.info(f"Got item: {item}")
|
2022-09-07 06:20:30 +00:00
|
|
|
items.append(item)
|
2022-09-13 21:17:46 +00:00
|
|
|
if items:
|
|
|
|
print("PROCESSING", len(items))
|
|
|
|
await process.spawn_processing_threads(items)
|