Skip to content

Commit

Permalink
code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Jan 14, 2025
1 parent ba4301f commit 59dfb05
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,17 @@ def _update_template(id, name, template_type, content, subject):
db.session.commit()


@notify_command(name="clear-redis-list")
@click.option("-n", "--name_of_list", required=True)
def clear_redis_list(name_of_list):
my_len_before = redis_store.llen(name_of_list)
redis_store.ltrim(name_of_list, 1, 0)
my_len_after = redis_store.llen(name_of_list)
current_app.logger.info(
f"Cleared redis list {name_of_list}. Before: {my_len_before} after {my_len_after}"
)


@notify_command(name="update-templates")
def update_templates():
with open(current_app.config["CONFIG_FILES"] + "/templates.json") as f:
Expand Down
2 changes: 0 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,8 +1717,6 @@ def serialize_for_redis(self, obj):
pass # do nothing because we don't have the message id yet
else:
fields[column.name] = value
current_app.logger.warning(f"FIELDS {fields}")
print(f"FIELDS {fields}", flush=True)

return fields
raise ValueError("Provided object is not a SQLAlchemy instance")
Expand Down
9 changes: 6 additions & 3 deletions notifications_utils/clients/redis/redis_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ class RedisClient:
active = False
scripts = {}

@classmethod
def pipeline(cls):
return cls.redis_store.pipeline()
def pipeline(self):
return self.redis_store.pipeline()

def init_app(self, app):
self.active = app.config.get("REDIS_ENABLED")
Expand Down Expand Up @@ -172,6 +171,10 @@ def llen(self, key):
if self.active:
return self.redis_store.llen(key)

def ltrim(self, key, start, end):
if self.active:
return self.redis_store.ltrim(key, start, end)

def delete(self, *keys, raise_exception=False):
keys = [prepare_value(k) for k in keys]
if self.active:
Expand Down

0 comments on commit 59dfb05

Please sign in to comment.