Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #34 from business-factory/feature-25196-forward-hu…
Browse files Browse the repository at this point in the history
…bspot-messages-to-both-master-and-staging

Forward messages from Hubspot to both master & staging Rabbit #25196
  • Loading branch information
miso-belica committed Sep 6, 2018
2 parents 1c570d1 + ca56845 commit f9ffd55
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 15 deletions.
6 changes: 6 additions & 0 deletions hooks/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def on_post(self, req, resp, scope):
class HubspotHooks:
def __init__(self):
self._publisher = services.publisher()
self._publisher_staging = services.publisher_staging()
self._logger = services.logger()

def on_post(self, req, resp):
Expand All @@ -59,6 +60,11 @@ def on_post(self, req, resp):
with self._publisher as publisher:
publisher.send_hubspot_event(payload)

# master Cpt. Hook instance should forward messages to both master & staging Rabbit, see https://is.roihunter.com/issues/25196
if self._publisher_staging:
with self._publisher_staging as publisher_staging:
publisher_staging.send_hubspot_event(payload)

resp.status = falcon.HTTP_200
except pika.exceptions.AMQPError:
self._logger.exception("Exception while publishing to RabbitMQ.")
Expand Down
15 changes: 15 additions & 0 deletions hooks/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,18 @@ def publisher():
settings.RABBIT_VIRTUAL_HOST,
settings.RABBIT_EXCHANGE
)


@lru_cache(maxsize=1)
def publisher_staging():
if settings.PROFILE == "staging":
return None

return RabbitPublisher(
settings.RABBIT_LOGIN_STAGING,
settings.RABBIT_PASSWORD_STAGING,
settings.RABBIT_HOST_STAGING,
settings.RABBIT_PORT_STAGING,
settings.RABBIT_VIRTUAL_HOST,
settings.RABBIT_EXCHANGE
)
10 changes: 5 additions & 5 deletions hooks/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

from ._settings_default import *

profile = environ.get("CAPTAINHOOK_PROFILE", "local")
PROFILE = environ.get("CAPTAINHOOK_PROFILE", "local")

if profile == "master":
if PROFILE == "master":
from ._settings_master import *
elif profile == "staging":
elif PROFILE == "staging":
from ._settings_staging import *
elif profile == "local":
elif PROFILE == "local":
try:
from ._settings_local import *
except ImportError:
Expand All @@ -20,4 +20,4 @@
)
)
else:
raise ValueError("Unsupported settings profile. Use one of {}. Given: '{}'.".format(("master", "staging", "local"), profile))
raise ValueError("Unsupported settings profile. Use one of {}. Given: '{}'.".format(("master", "staging", "local"), PROFILE))
14 changes: 10 additions & 4 deletions hooks/settings/_settings_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
DEVELOPMENT_MODE = get_env("DEVELOPMENT_MODE", default=True)
FACEBOOK_VERIFY_TOKEN = get_env("FACEBOOK_VERIFY_TOKEN", default="token")

GRAYLOG_HOST = get_env("GRAYLOG_HOST", default=None)
GRAYLOG_PORT = get_env("GRAYLOG_PORT", default=None)

RABBIT_VIRTUAL_HOST = "hooks"
RABBIT_EXCHANGE = "events"

RABBIT_LOGIN = get_env("RABBIT_LOGIN", default="guest")
RABBIT_PASSWORD = get_env("RABBIT_PASSWORD", default="guest")
RABBIT_HOST = get_env("RABBIT_HOST", default="localhost")
RABBIT_PORT = get_env("RABBIT_PORT", default=5672, convert=int)
RABBIT_VIRTUAL_HOST = "hooks"
RABBIT_EXCHANGE = "events"

GRAYLOG_HOST = get_env("GRAYLOG_HOST", default=None)
GRAYLOG_PORT = get_env("GRAYLOG_PORT", default=None)
RABBIT_LOGIN_STAGING = get_env("RABBIT_LOGIN_STAGING", default="guest")
RABBIT_PASSWORD_STAGING = get_env("RABBIT_PASSWORD_STAGING", default="guest")
RABBIT_HOST_STAGING = get_env("RABBIT_HOST_STAGING", default="localhost")
RABBIT_PORT_STAGING = get_env("RABBIT_PORT_STAGING", default=5672, convert=int)
2 changes: 2 additions & 0 deletions hooks/settings/_settings_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

GRAYLOG_HOST = "logs.roihunter.com"
GRAYLOG_PORT = 12212

RABBIT_PORT_STAGING = 32769
2 changes: 2 additions & 0 deletions hooks/settings/_settings_staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

GRAYLOG_HOST = "logs.roihunter.com"
GRAYLOG_PORT = 12212

RABBIT_PORT = 32769
22 changes: 19 additions & 3 deletions kubernetes/captain-hook-master-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,25 @@ spec:
name: captainhook-master-rabbit-secret
key: password
- name: CAPTAINHOOK_RABBIT_HOST
value: '35.233.65.128'
- name: CAPTAINHOOK_RABBIT_PORT
value: '5672'
valueFrom:
secretKeyRef:
name: captainhook-master-rabbit-host
key: secret
- name: CAPTAINHOOK_RABBIT_LOGIN_STAGING
valueFrom:
secretKeyRef:
name: captainhook-staging-rabbit-secret
key: username
- name: CAPTAINHOOK_RABBIT_PASSWORD_STAGING
valueFrom:
secretKeyRef:
name: captainhook-staging-rabbit-secret
key: password
- name: CAPTAINHOOK_RABBIT_HOST_STAGING
valueFrom:
secretKeyRef:
name: captainhook-staging-rabbit-host
key: secret
ports:
- containerPort: 8005
resources:
Expand Down
7 changes: 4 additions & 3 deletions kubernetes/captain-hook-staging-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ spec:
name: captainhook-staging-rabbit-secret
key: password
- name: CAPTAINHOOK_RABBIT_HOST
value: '195.201.160.243'
- name: CAPTAINHOOK_RABBIT_PORT
value: '32769'
valueFrom:
secretKeyRef:
name: captainhook-staging-rabbit-host
key: secret
ports:
- containerPort: 8005
imagePullSecrets:
Expand Down

0 comments on commit f9ffd55

Please sign in to comment.