381 import traceback |
381 import traceback |
382 traceback.print_exc() |
382 traceback.print_exc() |
383 raise Exception('Is the database initialised ? (cause: %s)' % ex) |
383 raise Exception('Is the database initialised ? (cause: %s)' % ex) |
384 return appschema |
384 return appschema |
385 |
385 |
|
386 def has_scheduler(self): |
|
387 """Return True if the repository has a scheduler attached and is able |
|
388 to register looping tasks. |
|
389 """ |
|
390 return self._scheduler is not None |
|
391 |
386 def run_scheduler(self): |
392 def run_scheduler(self): |
387 """Start repository scheduler after preparing the repository for that. |
393 """Start repository scheduler after preparing the repository for that. |
388 |
394 |
389 * trigger server startup hook, |
395 * trigger server startup hook, |
390 * start the scheduler *and block*. |
396 * start the scheduler *and block*. |
391 |
397 |
392 XXX Other startup related stuffs are done elsewhere. In Repository |
398 XXX Other startup related stuffs are done elsewhere. In Repository |
393 XXX __init__ or in external codes (various server managers). |
399 XXX __init__ or in external codes (various server managers). |
394 """ |
400 """ |
395 assert self._scheduler is not None, \ |
401 assert self.has_scheduler(), \ |
396 "This Repository is not intended to be used as a server" |
402 "This Repository is not intended to be used as a server" |
397 self.info( |
403 self.info( |
398 'starting repository scheduler with tasks: %s', |
404 'starting repository scheduler with tasks: %s', |
399 ', '.join(e.action.__name__ for e in self._scheduler.queue)) |
405 ', '.join(e.action.__name__ for e in self._scheduler.queue)) |
400 self._scheduler.run() |
406 self._scheduler.run() |
405 looping tasks can only be registered during repository initialization, |
411 looping tasks can only be registered during repository initialization, |
406 once done this method will fail. |
412 once done this method will fail. |
407 """ |
413 """ |
408 if self.config.repairing: |
414 if self.config.repairing: |
409 return |
415 return |
410 if self._scheduler is None: |
416 if not self.has_scheduler(): |
411 self.warning( |
417 self.warning( |
412 'looping task %s will not run in this process where repository ' |
418 'looping task %s will not run in this process where repository ' |
413 'has no scheduler; use "cubicweb-ctl scheduler <appid>" to ' |
419 'has no scheduler; use "cubicweb-ctl scheduler <appid>" to ' |
414 'have it running', func) |
420 'have it running', func) |
415 return |
421 return |