Skip to content

Commit

Permalink
[feat] Improve logging (#17)
Browse files Browse the repository at this point in the history
* [feat] Improve logging

* fix type

* bump version
  • Loading branch information
aquamatthias authored Oct 30, 2023
1 parent 7307bb0 commit 158b557
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion fixcloudutils/redis/event_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ async def cleanup_processed_messages(self) -> int:
log.info(f"Deleting processed or old messages from stream: {len(to_delete)}")
cleaned_messages += len(to_delete)
await self.redis.xdel(self.stream, *to_delete)
log.info(f"Cleaning up processed messages done. Cleaned {cleaned_messages} messages.")
if cleaned_messages > 0:
log.info(f"Cleaning up processed messages done. Cleaned {cleaned_messages} messages.")
return cleaned_messages

async def start(self) -> None:
Expand Down
15 changes: 9 additions & 6 deletions fixcloudutils/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Any, TypeVar, Dict, List, Type, AsyncContextManager
import logging
from typing import Any, TypeVar, Dict, List, Type, AsyncContextManager, Tuple

ServiceType = TypeVar("ServiceType", bound="Service")
T = TypeVar("T")
log = logging.getLogger("fixcloudutils.service")


class Service(AsyncContextManager[Any]):
Expand Down Expand Up @@ -59,8 +60,8 @@ def extend(self, **deps: Any) -> "Dependencies":
return self

@property
def services(self) -> List[AsyncContextManager[Any]]:
return [v for _, v in self.lookup.items() if isinstance(v, AsyncContextManager)]
def services(self) -> List[Tuple[str, AsyncContextManager[Any]]]:
return [(k, v) for k, v in self.lookup.items() if isinstance(v, AsyncContextManager)]

def service(self, name: str, clazz: Type[T]) -> T:
if isinstance(existing := self.lookup.get(name), clazz):
Expand All @@ -69,9 +70,11 @@ def service(self, name: str, clazz: Type[T]) -> T:
raise KeyError(f"Service {name} not found")

async def start(self) -> None:
for service in self.services:
for name, service in self.services:
log.info(f"Start service {name}.")
await service.__aenter__()

async def stop(self) -> None:
for service in reversed(self.services):
for name, service in reversed(self.services):
log.info(f"Stop service {name}.")
await service.__aexit__(None, None, None)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "fixcloudutils"
version = "1.7.1"
version = "1.8.0"
authors = [{ name = "Some Engineering Inc." }]
description = "Utilities for fixcloud."
license = { file = "LICENSE" }
Expand Down

0 comments on commit 158b557

Please sign in to comment.