| |
@@ -442,65 +442,43 @@
|
| |
data['id'] = erepo_id
|
| |
self.checkExternalRepo(data, arches, ts_cache)
|
| |
|
| |
- def currencyChecker(self, session):
|
| |
- """Continually checks repos for currency. Runs as a separate thread"""
|
| |
+ def threadLoop(self, session, name):
|
| |
+ """Wrapper for running thread handlers in a loop"""
|
| |
+ # we should be passed a subsession of main
|
| |
self.session = session
|
| |
- self.logger = logging.getLogger("koji.repo.currency")
|
| |
- self.logger.info('currencyChecker starting')
|
| |
+ handler = getattr(self, f'do_{name}')
|
| |
+ self.logger = logging.getLogger(f'koji.repo.{name}')
|
| |
+ self.logger.info(f'{name} thread starting')
|
| |
try:
|
| |
while True:
|
| |
- self.session.repo.updateEndEvents()
|
| |
- # TODO does this still need to be its own thread?
|
| |
+ handler()
|
| |
time.sleep(self.options.sleeptime)
|
| |
except Exception:
|
| |
- self.logger.exception('Error in currency checker thread')
|
| |
+ self.logger.exception(f'Error in {name} thread')
|
| |
raise
|
| |
finally:
|
| |
session.logout()
|
| |
|
| |
- def currencyExternalChecker(self, session):
|
| |
- """Continually checks repos for external repo currency. Runs as a separate thread"""
|
| |
- self.session = session
|
| |
- self.logger = logging.getLogger("koji.repo.currency_external")
|
| |
- self.logger.info('currencyExternalChecker starting')
|
| |
- try:
|
| |
- while True:
|
| |
- self.checkExternalRepos()
|
| |
- time.sleep(self.options.sleeptime)
|
| |
- except Exception:
|
| |
- self.logger.exception('Error in external currency checker thread')
|
| |
- raise
|
| |
- finally:
|
| |
- session.logout()
|
| |
+ def do_currency(self):
|
| |
+ """Checks repos for currency"""
|
| |
+ # this call can take a while
|
| |
+ self.session.repo.updateEndEvents()
|
| |
|
| |
- def regenLoop(self, session):
|
| |
- """Triggers regens as needed/possible. Runs in a separate thread"""
|
| |
- self.session = session
|
| |
- self.logger = logging.getLogger("koji.repo.regen")
|
| |
- self.logger.info('regenLoop starting')
|
| |
- try:
|
| |
- while True:
|
| |
- self.regenRepos()
|
| |
- time.sleep(self.options.sleeptime)
|
| |
- except Exception:
|
| |
- self.logger.exception('Error in regen thread')
|
| |
- raise
|
| |
- finally:
|
| |
- session.logout()
|
| |
+ def do_check_external(self):
|
| |
+ """Check external repos"""
|
| |
+ self.checkExternalRepos()
|
| |
|
| |
- def rmtreeLoop(self, session):
|
| |
- self.session = session
|
| |
- logger = logging.getLogger("koji.repo.rmtree")
|
| |
- try:
|
| |
- while True:
|
| |
- logger.debug('queue length: %d', len(self.delete_queue))
|
| |
- self.checkQueue()
|
| |
- time.sleep(self.options.sleeptime)
|
| |
- except Exception:
|
| |
- logger.exception('Error in rmtree thread')
|
| |
- raise
|
| |
- finally:
|
| |
- session.logout()
|
| |
+ def do_regen(self):
|
| |
+ """Triggers regens as needed/possible"""
|
| |
+ self.session.repo.checkQueue()
|
| |
+
|
| |
+ def do_autoregen(self):
|
| |
+ """Triggers automatic regens as needed/possible"""
|
| |
+ self.session.repo.autoRequests()
|
| |
+
|
| |
+ def do_rmtree(self):
|
| |
+ logger.debug('queue length: %d', len(self.delete_queue))
|
| |
+ self.checkQueue()
|
| |
|
| |
def pruneLocalRepos(self):
|
| |
# non-dist repos are always on the default volume
|
| |
@@ -648,43 +626,11 @@
|
| |
elif repo.state == koji.REPO_PROBLEM:
|
| |
repo.handle_problem()
|
| |
|
| |
- def regenRepos(self):
|
| |
- """Trigger repo requests as needed"""
|
| |
- self.session.repo.autoRequests()
|
| |
- self.session.repo.checkQueue()
|
| |
-
|
| |
-
|
| |
- def start_currency_checker(session, repomgr):
|
| |
- subsession = session.subsession()
|
| |
- thread = threading.Thread(name='currencyChecker',
|
| |
- target=repomgr.currencyChecker, args=(subsession,))
|
| |
- thread.daemon = True
|
| |
- thread.start()
|
| |
- return thread
|
| |
-
|
| |
-
|
| |
- def start_external_currency_checker(session, repomgr):
|
| |
- subsession = session.subsession()
|
| |
- thread = threading.Thread(name='currencyExternalChecker',
|
| |
- target=repomgr.currencyExternalChecker, args=(subsession,))
|
| |
- thread.daemon = True
|
| |
- thread.start()
|
| |
- return thread
|
| |
-
|
| |
-
|
| |
- def start_regen_loop(session, repomgr):
|
| |
- subsession = session.subsession()
|
| |
- thread = threading.Thread(name='regenLoop',
|
| |
- target=repomgr.regenLoop, args=(subsession,))
|
| |
- thread.daemon = True
|
| |
- thread.start()
|
| |
- return thread
|
| |
-
|
| |
|
| |
- def start_rmtree_loop(session, repomgr):
|
| |
+ def start_thread(session, repomgr, name):
|
| |
+ handler = getattr(repomgr, 'threadLoop')
|
| |
subsession = session.subsession()
|
| |
- thread = threading.Thread(name='rmtreeLoop',
|
| |
- target=repomgr.rmtreeLoop, args=(subsession,))
|
| |
+ thread = threading.Thread(name=name, target=handler, args=(subsession, name))
|
| |
thread.daemon = True
|
| |
thread.start()
|
| |
return thread
|
| |
@@ -697,29 +643,20 @@
|
| |
def shutdown(*args):
|
| |
raise SystemExit
|
| |
signal.signal(signal.SIGTERM, shutdown)
|
| |
- curr_chk_thread = start_currency_checker(session, repomgr)
|
| |
+ tnames = ['currency', 'regen', 'autoregen', 'rmtree']
|
| |
if options.check_external_repos:
|
| |
- curr_ext_chk_thread = start_external_currency_checker(session, repomgr)
|
| |
- regen_thread = start_regen_loop(session, repomgr)
|
| |
- rmtree_thread = start_rmtree_loop(session, repomgr)
|
| |
+ tnames.append('check_external')
|
| |
+ threads = {name: start_thread(session, repomgr, name) for name in tnames}
|
| |
logger.info("Entering main loop")
|
| |
while True:
|
| |
try:
|
| |
repomgr.updateRepos()
|
| |
repomgr.printState()
|
| |
repomgr.pruneLocalRepos()
|
| |
- if not curr_chk_thread.is_alive():
|
| |
- logger.error("Currency checker thread died. Restarting it.")
|
| |
- curr_chk_thread = start_currency_checker(session, repomgr)
|
| |
- if options.check_external_repos and not curr_ext_chk_thread.is_alive():
|
| |
- logger.error("External currency checker thread died. Restarting it.")
|
| |
- curr_ext_chk_thread = start_external_currency_checker(session, repomgr)
|
| |
- if not regen_thread.is_alive():
|
| |
- logger.error("Regeneration thread died. Restarting it.")
|
| |
- regen_thread = start_regen_loop(session, repomgr)
|
| |
- if not rmtree_thread.is_alive():
|
| |
- logger.error("rmtree thread died. Restarting it.")
|
| |
- rmtree_thread = start_rmtree_loop(session, repomgr)
|
| |
+ for name in tnames:
|
| |
+ if not threads[name].is_alive():
|
| |
+ logger.error(f'{name} thread died. Restarting it.')
|
| |
+ threads[name] = start_thread(session, repomgr, name)
|
| |
except KeyboardInterrupt:
|
| |
logger.warning("User exit")
|
| |
break
|
| |
A single kojira thread was running both
repo.autoRequests
andrepo.checkQueue
. On some systems, the autoRequests call can take a while, resulting is slower response times for repo requests.Rather than duplicate the thread boilerplate yet another time, I unified it, reducing quite a bit of repetitive code.
Also added a unit test and a couple minor fixes
Fixes https://pagure.io/koji/issue/4278