Skip to content

Commit

Permalink
fix: handle exceptions on prometheus operations
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhaidong committed Feb 14, 2025
1 parent 329d1f4 commit f8c6e28
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7.15", "3.8.12", "3.9.12"]
python-version: ["3.9", "3.10"]
steps:
- uses: actions/checkout@v3
# memcached
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

---

## [1.2.2] - 2025-01-14

changed:

- handle exceptions on prometheus operations

## [1.2.1] - 2024-04-29

### Added:
Expand Down
2 changes: 1 addition & 1 deletion cachext/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.1'
__version__ = '1.2.2'
12 changes: 8 additions & 4 deletions cachext/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def wrapper(*args, **kwargs):
self.monitor_label_builder(f, *args, **kwargs)
)
if self.request_counter:
# Increment request counter.
self.request_counter.labels(*labels).inc()
try:
self.request_counter.labels(*labels).inc()
except Exception as e:
print("request_counter.labels(*labels).inc() error: ", e)
if rv is None:
rv = f(*args, **kwargs)
if self.cache_none and rv is None:
Expand All @@ -78,8 +80,10 @@ def wrapper(*args, **kwargs):
if callable(self.fallbacked):
self.fallbacked(wrapper, rv, *args, **kwargs)
elif self.hit_counter:
# Increment hit counter.
self.hit_counter.labels(*labels).inc()
try:
self.hit_counter.labels(*labels).inc()
except Exception as e:
print("hit_counter.labels(*labels).inc() error: ", e)
if self.cache_none and rv is CacheNone:
return None
return rv
Expand Down

0 comments on commit f8c6e28

Please sign in to comment.