async def __ainit__(self) -> None: log.info('Session scheduler started') self.registry.event_dispatcher.consume('session_enqueued', None, self.schedule) self.registry.event_dispatcher.consume('session_terminated', None, self.schedule) self.registry.event_dispatcher.consume('instance_started', None, self.schedule) self.registry.event_dispatcher.consume('do_schedule', None, self.schedule) redis_url = self.shared_config.get_redis_url(db=REDIS_STREAM_DB) self.lock_manager = aioredlock.Aioredlock( [str(redis_url)], # we have explicit semantics: temporary locking failure -> try at the next chance, # such as scheduling timer ticks or upon scheduling events retry_count=2, ) self.timer_redis = await aioredis.create_redis(str(redis_url)) self.schedule_timer = GlobalTimer( self.timer_redis, self.event_dispatcher, 'do_schedule', interval=10.0, ) await self.schedule_timer.join()
async def get_lock_manager(cls) -> aioredlock.Aioredlock: if cls.lock_manager is not None: return cls.lock_manager cls.lock_manager = aioredlock.Aioredlock([await cls.get_redis()], lock_timeout=300, retry_count=3, retry_delay_min=30, retry_delay_max=90) return cls.lock_manager
async def __ainit__(self) -> None: log.info('Session scheduler started') self.tick_task = asyncio.create_task(self.generate_scheduling_tick()) self.registry.event_dispatcher.consume('kernel_enqueued', None, self.schedule) self.registry.event_dispatcher.consume('kernel_terminated', None, self.schedule) self.registry.event_dispatcher.consume('instance_started', None, self.schedule) self.registry.event_dispatcher.consume('do_schedule', None, self.schedule) # TODO: add events for resource configuration changes and subscribe them here. self.lock_manager = aioredlock.Aioredlock([ {'host': str(self.config['redis']['addr'][0]), 'port': self.config['redis']['addr'][1], 'password': self.config['redis']['password'] if self.config['redis']['password'] else None, 'db': REDIS_LIVE_DB}, ])
async def init(app: web.Application) -> None: app['log_cleanup_lock'] = aioredlock.Aioredlock([ { 'host': str(app['config']['redis']['addr'][0]), 'port': app['config']['redis']['addr'][1], 'password': app['config']['redis']['password'] if app['config']['redis']['password'] else None, 'db': REDIS_LIVE_DB }, ]) app['log_cleanup_task'] = aiotools.create_timer( functools.partial(log_cleanup_task, app), 5.0)
async def create_pool(cls, config: dict) -> None: """ Creates and connects the pool object. Args: config (dict): The config dictionary that should be passed directly to :func:`aioredis.create_redis_pool` directly as kwargs. """ cls.config = config.copy() modified_config = config.copy() if modified_config.pop('enabled', True) is False: raise NotImplementedError( "The Redis connection has been disabled.") address = modified_config.pop('host'), modified_config.pop('port') cls.pool = await aioredis.create_redis_pool(address, **modified_config) cls.lock_manager = aioredlock.Aioredlock([cls.pool])
async def __ainit__(self) -> None: log.info('Session scheduler started') self.tick_task = asyncio.create_task(self.generate_scheduling_tick()) self.registry.event_dispatcher.consume('session_enqueued', None, self.schedule) self.registry.event_dispatcher.consume('session_terminated', None, self.schedule) self.registry.event_dispatcher.consume('instance_started', None, self.schedule) self.registry.event_dispatcher.consume('do_schedule', None, self.schedule) # TODO: add events for resource configuration changes and subscribe them here. self.lock_manager = aioredlock.Aioredlock( [ {'host': str(self.config['redis']['addr'][0]), 'port': self.config['redis']['addr'][1], 'password': self.config['redis']['password'] if self.config['redis']['password'] else None, 'db': REDIS_LIVE_DB}, ], # we have explicit semantics: temporary locking failure -> try at the next chance, # such as scheduling timer ticks or upon scheduling events retry_count=2, )
def __init__(self, redis_host: str, redis_port: str, lock_timeout: int = 60): self.aiored_lock = \ aioredlock.Aioredlock([(redis_host, redis_port)], lock_timeout=lock_timeout)
async def on_startup() -> None: app.state.redis = await aioredis.create_redis_pool(settings.APP_REDIS_DSN) app.state.lock = aioredlock.Aioredlock([app.state.redis]) db = SessionLocal() await crud.user_cachedb.load(db, app.state.redis) db.close()
async def init(app: web.Application) -> None: redis_url = app['shared_config'].get_redis_url() app['log_cleanup_lock'] = aioredlock.Aioredlock([str(redis_url)]) app['log_cleanup_task'] = aiotools.create_timer( functools.partial(log_cleanup_task, app), 5.0)