351 None, sys.exc_info()[-1] |
351 None, sys.exc_info()[-1] |
352 finally: |
352 finally: |
353 session.close() |
353 session.close() |
354 self.set_schema(appschema) |
354 self.set_schema(appschema) |
355 |
355 |
356 def start_looping_tasks(self): |
356 |
|
357 def _prepare_startup(self): |
|
358 """Prepare "Repository as a server" for startup. |
|
359 |
|
360 * trigger server startup hook, |
|
361 * register session clean up task. |
|
362 """ |
357 if not (self.config.creating or self.config.repairing |
363 if not (self.config.creating or self.config.repairing |
358 or self.config.quick_start): |
364 or self.config.quick_start): |
359 # call instance level initialisation hooks |
365 # call instance level initialisation hooks |
360 self.hm.call_hooks('server_startup', repo=self) |
366 self.hm.call_hooks('server_startup', repo=self) |
361 # register a task to cleanup expired session |
367 # register a task to cleanup expired session |
362 self.cleanup_session_time = self.config['cleanup-session-time'] or 60 * 60 * 24 |
368 self.cleanup_session_time = self.config['cleanup-session-time'] or 60 * 60 * 24 |
363 assert self.cleanup_session_time > 0 |
369 assert self.cleanup_session_time > 0 |
364 cleanup_session_interval = min(60*60, self.cleanup_session_time / 3) |
370 cleanup_session_interval = min(60*60, self.cleanup_session_time / 3) |
365 self.looping_task(cleanup_session_interval, self.clean_sessions) |
371 self._tasks_manager.add_looping_task(cleanup_session_interval, |
|
372 self.clean_sessions) |
|
373 |
|
374 def start_looping_tasks(self): |
|
375 """Actual "Repository as a server" startup. |
|
376 |
|
377 * trigger server startup hook, |
|
378 * register session clean up task, |
|
379 * start all tasks. |
|
380 |
|
381 XXX Other startup related stuffs are done elsewhere. In Repository |
|
382 XXX __init__ or in external codes (various server managers). |
|
383 """ |
|
384 self._prepare_startup() |
366 self._tasks_manager.start() |
385 self._tasks_manager.start() |
367 |
386 |
368 def looping_task(self, interval, func, *args): |
387 def looping_task(self, interval, func, *args): |
369 """register a function to be called every `interval` seconds. |
388 """register a function to be called every `interval` seconds. |
370 |
389 |