Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reloading hook modules in arbiter.reload_from_config function #871

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion circus/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def reload_from_config(self, config_file=None, inside_circusd=False):
if added_sn or deleted_sn:
# make sure all existing watchers get the new sockets in
# their attributes and get the old removed
# XXX: is this necessary? self.sockets is an mutable
# XXX: is this necessary? self.sockets is a mutable
# object
for watcher in self.iter_watchers():
# XXX: What happens as initalize is called on a
Expand Down Expand Up @@ -399,6 +399,9 @@ def reload_from_config(self, config_file=None, inside_circusd=False):
changed_wn.add(n)
deleted_wn.add(n)
added_wn.add(n)
else:
# reload hooks of unchanged watcher
w.reload_hooks()

# delete watchers
for n in deleted_wn:
Expand All @@ -417,6 +420,9 @@ def reload_from_config(self, config_file=None, inside_circusd=False):
yield self.start_watcher(w)
self.watchers.append(w)
self._watchers_names[w.name.lower()] = w
# when the watcher was changed reload it's hooks
if n in changed_wn:
w.reload_hooks()

@classmethod
def load_from_config(cls, config_file, loop=None):
Expand Down
5 changes: 5 additions & 0 deletions circus/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ def _resolve_hooks(self, hooks):
for name, (callable_or_name, ignore_failure) in hooks.items():
self._resolve_hook(name, callable_or_name, ignore_failure)

def reload_hooks(self, ignore_failure=False):
for hook_name, func in self.hooks.items():
hook = func.__module__ + ':' + func.__name__
self._resolve_hook(hook_name, hook, ignore_failure, reload_module=True)

@property
def pending_socket_event(self):
return self.on_demand and not self.arbiter.socket_event
Expand Down