Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/updater/consumer.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import logging | import logging | ||||
from abc import ABCMeta, abstractmethod | from abc import ABCMeta, abstractmethod | ||||
from swh.scheduler.updater.backend import SchedulerUpdaterBackend | |||||
class UpdaterConsumer(metaclass=ABCMeta): | class UpdaterConsumer(metaclass=ABCMeta): | ||||
"""Event consumer | """Event consumer | ||||
""" | """ | ||||
def __init__(self, batch=1000, backend_class=SchedulerUpdaterBackend, | def __init__(self, backend, batch_cache_write=1000): | ||||
log_class='swh.scheduler.updater.consumer.UpdaterConsumer'): | |||||
super().__init__() | super().__init__() | ||||
self._reset_cache() | self._reset_cache() | ||||
self.backend = backend_class() | self.backend = backend | ||||
self.batch = batch | self.batch = int(batch_cache_write) | ||||
logging.basicConfig(level=logging.DEBUG) | logging.basicConfig(level=logging.DEBUG) | ||||
self.log = logging.getLogger(log_class) | self.log = logging.getLogger('%s.%s' % ( | ||||
self.__class__.__module__, self.__class__.__name__)) | |||||
def _reset_cache(self): | def _reset_cache(self): | ||||
"""Reset internal cache. | """Reset internal cache. | ||||
""" | """ | ||||
self.count = 0 | self.count = 0 | ||||
self.seen_events = set() | self.seen_events = set() | ||||
self.events = [] | self.events = [] | ||||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |