feat: add source websites with automated endpoint analysis, target queue dispatch ordering, and markdown styling
This commit is contained in:
+17
-2
@@ -30,11 +30,26 @@ class RedisQueue:
|
||||
await self.client.rpush(key, raw_json)
|
||||
logger.info(f"Enqueued post {payload.get('post_id')} to Target #{target_id} queue [{key}]")
|
||||
|
||||
async def pop_target_post(self, target_id: int) -> Optional[Dict[str, Any]]:
|
||||
async def pop_target_post(self, target_id: int, dispatch_order: str = "order") -> Optional[Dict[str, Any]]:
|
||||
if not self.client:
|
||||
await self.connect()
|
||||
key = self._get_target_key(target_id)
|
||||
raw = await self.client.lpop(key)
|
||||
|
||||
if dispatch_order == "random":
|
||||
import random
|
||||
length = await self.client.llen(key)
|
||||
if length == 0:
|
||||
return None
|
||||
if length == 1:
|
||||
raw = await self.client.lpop(key)
|
||||
else:
|
||||
idx = random.randint(0, length - 1)
|
||||
raw = await self.client.lindex(key, idx)
|
||||
if raw:
|
||||
await self.client.lrem(key, 1, raw)
|
||||
else:
|
||||
raw = await self.client.lpop(key)
|
||||
|
||||
if raw:
|
||||
try:
|
||||
return json.loads(raw)
|
||||
|
||||
Reference in New Issue
Block a user