Skip to content

Commit

Permalink
feat: dev comments (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Mar 3, 2023
1 parent 8044982 commit a84cc59
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 7 additions & 1 deletion a_sync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def get_default_executor() -> Executor:
executor=default_sync_executor,
)

#####################
# Default Modifiers #
#####################

# User configurable default modifiers to be applied to any a_sync decorated function if you do not specify kwarg values for each modifier.

DEFAULT_MODE: DefaultMode = os.environ.get("A_SYNC_DEFAULT_MODE") # type: ignore [assignment]
CACHE_TYPE: CacheType = typ if (typ := os.environ.get("A_SYNC_CACHE_TYPE", "").lower()) else null_modifiers['cache_type']
CACHE_TYPED = bool(os.environ.get("A_SYNC_CACHE_TYPED"))
Expand All @@ -39,7 +45,7 @@ def get_default_executor() -> Executor:
RUNS_PER_MINUTE = rpm if (rpm := int(os.environ.get("A_SYNC_RUNS_PER_MINUTE", 0))) else null_modifiers['runs_per_minute']
SEMAPHORE = rpm if (rpm := int(os.environ.get("A_SYNC_SEMAPHORE", 0))) else null_modifiers['semaphore']

default_modifiers = ModifierKwargs(
user_set_default_modifiers = ModifierKwargs(
default=DEFAULT_MODE,
cache_type=CACHE_TYPE,
cache_typed=CACHE_TYPED,
Expand Down
12 changes: 6 additions & 6 deletions a_sync/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ def a_sync( # type: ignore [misc]
lib defaults:
async settings
cache_type: CacheType = None,
cache_typed: bool = False,
ram_cache_maxsize: Optional[int] = -1,
ram_cache_ttl: Optional[int] = None,
runs_per_minute: Optional[int] = None,
semaphore: SemaphoreSpec = semaphores.dummy_semaphore,
cache_type: CacheType = None, - This can be None or 'memory'. 'memory' is a lru cache which can be modified with the 'cache_typed','ram_cache_maxsize','ram_cache_ttl' modifiers.
cache_typed: bool = False, - Set to True if you want types considered treated for cache keys. ie with cache_typed=True, Decimal(0) and 0 will be considered separate keys.
ram_cache_maxsize: Optional[int] = -1, - The maxsize for your lru cache. None if cache is unbounded. If you set this value without specifying a cache type, 'memory' will automatically be applied.
ram_cache_ttl: Optional[int] = None, - The ttl for items in your lru cache. Set to None. If you set this value without specifying a cache type, 'memory' will automatically be applied.
runs_per_minute: Optional[int] = None, - Setting this value enables a rate limiter for the decorated function.
semaphore: SemaphoreSpec = None, - drop in a Semaphore for your async defined functions.
sync settings
executor: Executor = config.default_sync_executor
Expand Down
4 changes: 2 additions & 2 deletions a_sync/modifiers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from a_sync import semaphores
from a_sync._typing import *
from a_sync.config import default_modifiers, null_modifiers
from a_sync.config import user_set_default_modifiers, null_modifiers
from a_sync.modifiers import cache, limiter

valid_modifiers = [key for key in ModifierKwargs.__annotations__ if not key.startswith('_') and not key.endswith('_')]
Expand Down Expand Up @@ -87,4 +87,4 @@ def __getitem__(self, modifier_key: str):
return self._modifiers[modifier_key] # type: ignore [literal-required]

nulls = ModifierManager(**null_modifiers)
user_defaults = ModifierManager(**default_modifiers)
user_defaults = ModifierManager(**user_set_default_modifiers)

0 comments on commit a84cc59

Please sign in to comment.