Created
September 5, 2016 17:18
-
-
Save eihli/6791c73889c054e0f49b9b15b970c083 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from circus.plugins import CircusPlugin | |
from circus import logger | |
from zmq.eventloop import ioloop | |
import time | |
import pdb | |
class CircusWatcher(CircusPlugin): | |
name = 'circus_watcher' | |
def __init__(self, *args, **config): | |
super(CircusWatcher, self).__init__(*args, **config) | |
self.name = config.get('name') | |
self.watcher = config.get('watcher') | |
self.loop_rate = int(self.config.get('loop_rate', 1)) | |
self.restart_time = time.time() | |
def is_modified(self, filename): | |
mtime = os.stat(filename).st_mtime | |
if mtime > self.restart_time: | |
return True | |
return False | |
def look_after(self): | |
filename = self.config.get('watch_file') | |
if self.is_modified(filename): | |
logger.info('%s modified. Restarting.', filename) | |
self.restart_time = time.time() | |
self.call('restart', name=self.watcher) | |
def handle_init(self): | |
self.period = ioloop.PeriodicCallback(self.look_after, | |
self.loop_rate * 1000, | |
self.loop) | |
self.period.start() | |
def handle_stop(self): | |
self.period.stop() | |
def handle_recv(self, data): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment