Skip to content

Commit

Permalink
new diffusion scope using BUS_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Oct 3, 2018
1 parent fce328a commit 2a9b139
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ to store the preferences (using shelve)
#### Bus

* `BUS` (`str`) - Defines the bus manager to be used (eg: `memory`, `redis`)
* `BUS_NAME` (`str`) - Global name used to create different diffusion scopes for different bus contexts (default: `global`)

#### Session

Expand Down
7 changes: 5 additions & 2 deletions src/appier/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import pickle
import threading

from . import config
from . import redisdb
from . import component
from . import exceptions
Expand Down Expand Up @@ -103,7 +104,7 @@ def bind(self, name, method):
methods.append(method)
self._events[name] = methods
channel = self._to_channel(name)
self._pubsub.subscribe(channel)
self._pubsub.subscribe(self._name + channel)

def unbind(self, name, method = None):
methods = self._events.get(name, [])
Expand All @@ -122,6 +123,8 @@ def trigger(self, name, *args, **kwargs):

def _load(self, *args, **kwargs):
Bus._load(self, *args, **kwargs)
self._name = config.conf("BUS_NAME", "global")
self._name = kwargs.pop("name", self._name)
self._serializer = kwargs.pop("serializer", self.__class__.SERIALIZER)
self._global_channel = kwargs.pop("global_channel", self.__class__.GLOBAL_CHANNEL)
self._events = dict()
Expand All @@ -137,7 +140,7 @@ def _open(self):
self._redis = redisdb.get_connection()
self._redis.ping()
self._pubsub = self._redis.pubsub()
self._pubsub.subscribe(self._global_channel)
self._pubsub.subscribe(self._name + self._global_channel)
self._listener = RedisListener(self)
self._listener.start()

Expand Down

0 comments on commit 2a9b139

Please sign in to comment.