Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion maxim/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .cache import MaximCache
from .cache import AsyncMaximCache, MaximCache
from .inMemory import MaximInMemoryCache

__all__ = [
"MaximCache",
"MaximInMemoryCache",
"AsyncMaximCache",
]
32 changes: 23 additions & 9 deletions maxim/cache/cache.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
from abc import ABC, abstractmethod
from typing import List, Optional


class MaximCache():
class MaximCache(ABC):
@abstractmethod
def get_all_keys(self) -> List[str]: ...

def get_all_keys(self) -> List[str]:
return []
@abstractmethod
def get(self, key: str) -> Optional[str]: ...

def get(self, key: str) -> Optional[str]:
pass
@abstractmethod
def set(self, key: str, value: str) -> None: ...

def set(self, key: str, value: str) -> None:
pass
@abstractmethod
def delete(self, key: str) -> None: ...

def delete(self, key: str) -> None:
pass

class AsyncMaximCache(ABC):
@abstractmethod
async def a_get_all_keys(self) -> List[str]: ...

@abstractmethod
async def a_get(self, key: str) -> Optional[str]: ...

@abstractmethod
async def a_set(self, key: str, value: str) -> None: ...

@abstractmethod
async def a_delete(self, key: str) -> None: ...
4 changes: 3 additions & 1 deletion maxim/cache/inMemory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import List, Optional

from .cache import MaximCache

class MaximInMemoryCache():

class MaximInMemoryCache(MaximCache):
def __init__(self):
self.cache = {}

Expand Down
4 changes: 2 additions & 2 deletions maxim/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,11 @@ def id(self):
"""
return self._id

def flush(self):
def flush(self, sync: bool = False):
"""
Flushes the writer.
"""
self.writer.flush()
self.writer.flush(sync)

def cleanup(self):
"""
Expand Down
14 changes: 7 additions & 7 deletions maxim/logger/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def commit(self, log: CommitLog):
if self.queue.qsize() > self.max_in_memory_logs:
self.flush()

def flush_upload_attachment_logs(self):
def flush_upload_attachment_logs(self, sync: bool = False):
"""
Flush all queued attachments to the Maxim API.

Expand All @@ -505,13 +505,13 @@ def flush_upload_attachment_logs(self):
scribe().debug(
f"[MaximSDK] Flushing attachments to server {time.strftime('%Y-%m-%dT%H:%M:%S')} with {len(items)} items"
)
if self.is_running_on_lambda():
if self.is_running_on_lambda() or sync:
self.upload_attachments(items)
else:
self.upload_executor.submit(self.upload_attachments, items)
scribe().debug(f"[MaximSDK] Flushed {len(items)} attachments")

def flush_commit_logs(self):
def flush_commit_logs(self, sync: bool = False):
"""
Flush all queued commit logs to the Maxim API.

Expand All @@ -531,18 +531,18 @@ def flush_commit_logs(self):
for item in items:
scribe().debug(f"[MaximSDK] {item.serialize()}")
# if we are running on lambda - we will flush without submitting to the executor
if self.is_running_on_lambda():
if self.is_running_on_lambda() or sync:
self.flush_logs(items)
else:
self.executor.submit(self.flush_logs, items)
scribe().debug(f"[MaximSDK] Flushed {len(items)} logs")

def flush(self):
def flush(self, sync: bool = False):
"""
Flush all queued logs to the Maxim API.
"""
self.flush_commit_logs()
self.flush_upload_attachment_logs()
self.flush_commit_logs(sync)
self.flush_upload_attachment_logs(sync)

def cleanup(self):
"""
Expand Down
Loading