Esempio n. 1
0
 def __init__(self, events_es=None, redis=None):
     self.es = events_es or es_factory.connect("events")
     self._metrics = EventMetrics(self.es)
     self._skip_iteration_for_metric = set(
         config.get("services.events.ignore_iteration.metrics", [])
     )
     self.redis = redis or redman.connection("apiserver")
     self.debug_images_iterator = DebugImagesIterator(es=self.es, redis=self.redis)
Esempio n. 2
0
 def __init__(self, es=None, redis=None):
     self.es_client = es or es_factory.connect("workers")
     self.redis = redis or redman.connection("workers")
     self._stats = WorkerStats(self.es_client)
Esempio n. 3
0
import time
from contextlib import contextmanager
from time import sleep

from redis_manager import redman

_redis = redman.connection("apiserver")


@contextmanager
def distributed_lock(name: str, timeout: int, max_wait: int = 0):
    """
    Context manager that acquires a distributed lock on enter
    and releases it on exit. The has a ttl equal to timeout seconds
    If the lock can not be acquired for wait seconds (defaults to timeout * 2)
    then the exception is thrown
    """
    lock_name = f"dist_lock_{name}"
    start = time.time()
    max_wait = max_wait or timeout * 2
    while not _redis.set(lock_name, value="", ex=timeout, nx=True):
        sleep(1)
        if time.time() - start > max_wait:
            raise Exception(
                f"Could not acquire {name} lock for {max_wait} seconds")
    try:
        yield
    finally:
        _redis.delete(lock_name)
Esempio n. 4
0
 def __init__(self, es=None, redis=None):
     self.es_client = es if es is not None else es_factory.connect(
         "workers")
     self.redis = redis if redis is not None else redman.connection(
         "workers")
     self._stats = WorkerStats(self.es_client)
Esempio n. 5
0
 def __init__(self, redis=None):
     self.redis = redis or redman.connection("apiserver")
     self._task_tags = _TagsCache(Task, self.redis)
     self._model_tags = _TagsCache(Model, self.redis)
Esempio n. 6
0
 def __init__(self, redis=None):
     self.redis = redis or redman.connection("apiserver")