Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:stored-augment-type-in-redis #46

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion commons/cache/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class RedisCache:
# key to figure out how many workers are working
_num_workers_active_key: str = "num_workers_active"
_encoding: str = "utf-8"
# key to map ID to augment_type
_augment_type_key: str = "augment_type"
redis: Redis # pyright: ignore[reportMissingTypeArgument]

def __new__(cls) -> "RedisCache":
Expand Down Expand Up @@ -125,8 +127,18 @@ async def enqueue(self, data: Any) -> int:

# keep the historical data as is
# use uuid7 so keys in redis are sorted by time
hist_key = self._build_key(self._hist_key_prefix, uuid_utils.uuid7().__str__())
redis_task_id = uuid_utils.uuid7().__str__()
hist_key = self._build_key(self._hist_key_prefix, redis_task_id)
try:
# collect augment_type and store in redis
augment_type = data["augment_type"]
json_string = f'{{"augment_type": "{augment_type}"}}'

first_cid = data["responses"][0]["cid"]
augment_type_key = self._build_key(self._augment_type_key, first_cid)
logger.debug(f"Writing augment_type into {augment_type_key}")
await self.redis.set(augment_type_key, json_string)

logger.debug(f"Writing persistent data into {hist_key}")
# place into persistent key
str_data = json.dumps(jsonable_encoder(data)).encode(self._encoding)
Expand Down