Drop cancel_q from the monitor() function

Not needed, builds are canceled by writing a 'CANCEL' file in the results
directory.
This commit is contained in:
Brian C. Lane 2018-02-08 11:48:13 -08:00
parent 166350fcb6
commit 9603c866af
2 changed files with 12 additions and 12 deletions

View File

@ -35,9 +35,13 @@ from pylorax.installer import novirt_install
from pylorax.sysutils import joinpaths from pylorax.sysutils import joinpaths
# TODO needs a quit queue to cleanly manage quitting # TODO needs a quit queue to cleanly manage quitting
def monitor(cfg, cancel_q): def monitor(cfg):
""" Monitor the queue for new compose requests """ Monitor the queue for new compose requests
:param cfg: Configuration settings
:type cfg: ComposerConfig
:returns: Does not return
The queue has 2 subdirectories, new and run. When a compose is ready to be run The queue has 2 subdirectories, new and run. When a compose is ready to be run
a symlink to the uniquely named results directory should be placed in ./queue/new/ a symlink to the uniquely named results directory should be placed in ./queue/new/
@ -50,9 +54,9 @@ def monitor(cfg, cancel_q):
If the system is restarted while a compose is running it will move any old symlinks If the system is restarted while a compose is running it will move any old symlinks
from ./queue/run/ to ./queue/new/ and rerun them. from ./queue/run/ to ./queue/new/ and rerun them.
""" """
def queue_sort(job): def queue_sort(uuid):
"""Sort the queue entries by their mtime, not their names""" """Sort the queue entries by their mtime, not their names"""
return os.stat(joinpaths(cfg.composer_dir, "queue/new", job)).st_mtime return os.stat(joinpaths(cfg.composer_dir, "queue/new", uuid)).st_mtime
# Move any symlinks in the run queue back to the new queue # Move any symlinks in the run queue back to the new queue
for link in os.listdir(joinpaths(cfg.composer_dir, "queue/run")): for link in os.listdir(joinpaths(cfg.composer_dir, "queue/run")):
@ -62,15 +66,15 @@ def monitor(cfg, cancel_q):
log.debug("Moved unfinished compose %s back to new state", src) log.debug("Moved unfinished compose %s back to new state", src)
while True: while True:
jobs = sorted(os.listdir(joinpaths(cfg.composer_dir, "queue/new")), key=queue_sort) uuids = sorted(os.listdir(joinpaths(cfg.composer_dir, "queue/new")), key=queue_sort)
# Pick the oldest and move it into ./run/ # Pick the oldest and move it into ./run/
if not jobs: if not uuids:
# No composes left to process, sleep for a bit # No composes left to process, sleep for a bit
time.sleep(30) time.sleep(30)
else: else:
src = joinpaths(cfg.composer_dir, "queue/new", jobs[0]) src = joinpaths(cfg.composer_dir, "queue/new", uuids[0])
dst = joinpaths(cfg.composer_dir, "queue/run", jobs[0]) dst = joinpaths(cfg.composer_dir, "queue/run", uuids[0])
try: try:
os.rename(src, dst) os.rename(src, dst)
except OSError: except OSError:

View File

@ -34,8 +34,6 @@ from threading import Lock
from gevent import socket from gevent import socket
from gevent.wsgi import WSGIServer from gevent.wsgi import WSGIServer
from pyanaconda.queue import QueueFactory
from pylorax import vernum from pylorax import vernum
from pylorax.api.config import configure, make_yum_dirs from pylorax.api.config import configure, make_yum_dirs
from pylorax.api.queue import monitor from pylorax.api.queue import monitor
@ -219,10 +217,8 @@ if __name__ == '__main__':
listener.listen(1) listener.listen(1)
# Start queue monitor thread as root # Start queue monitor thread as root
cancel_q = QueueFactory("cancel")
cancel_q.addMessage("cancel", 0)
cfg = DataHolder(composer_dir=lib_dir, uid=uid, gid=gid) cfg = DataHolder(composer_dir=lib_dir, uid=uid, gid=gid)
p = mp.Process(target=monitor, args=(cfg, cancel_q)) p = mp.Process(target=monitor, args=(cfg,))
p.daemon = True p.daemon = True
p.start() p.start()