Commit 6b928715 by Bach Dániel

stop celery on SIGINT

parent da7e0963
......@@ -3,13 +3,30 @@ from twisted.internet import reactor, inotify
from twisted.python import filepath
from agentcelery import celery
from protocol import inotify_handler
from os import getenv
from os import getenv, listdir, path
import logging
SOCKET_DIR = getenv('SOCKET_DIR', '/var/lib/libvirt/serial')
old_install_platform_tweaks = Worker.install_platform_tweaks
def install_platform_tweaks(self, worker):
self.worker = worker
old_install_platform_tweaks(self, worker)
Worker.install_platform_tweaks = install_platform_tweaks
def reactor_started():
for f in listdir(SOCKET_DIR):
f = path.join(SOCKET_DIR, f)
inotify_handler(None, filepath.FilePath(f), None)
def reactor_stopped(worker):
worker.worker.stop()
def main():
w = Worker(app=celery, concurrency=1,
pool_cls='threads',
......@@ -19,6 +36,8 @@ def main():
notifier.startReading()
notifier.watch(filepath.FilePath(SOCKET_DIR),
callbacks=[inotify_handler])
reactor.callWhenRunning(reactor_started)
reactor.addSystemEventTrigger("before", "shutdown", reactor_stopped, w)
reactor.run()
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment