mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
Compare commits
2 Commits
56ef7ed243
...
tobys-keep
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb808112d5 | ||
|
|
ab92618250 |
@@ -62,6 +62,7 @@ class AwsSesClient(EmailClient):
|
|||||||
# before-call, after-call, after-call-error, request-created, response-received
|
# before-call, after-call, after-call-error, request-created, response-received
|
||||||
self._client.meta.events.register('request-created.ses.SendEmail', self.ses_request_created_hook)
|
self._client.meta.events.register('request-created.ses.SendEmail', self.ses_request_created_hook)
|
||||||
self._client.meta.events.register('response-received.ses.SendEmail', self.ses_response_received_hook)
|
self._client.meta.events.register('response-received.ses.SendEmail', self.ses_response_received_hook)
|
||||||
|
self._client.meta.events.register('before-call.ses', self.ses_inject_connection_header)
|
||||||
|
|
||||||
def ses_request_created_hook(self, **kwargs):
|
def ses_request_created_hook(self, **kwargs):
|
||||||
# request created may be called multiple times if the request auto-retries. We want to count all these as the
|
# request created may be called multiple times if the request auto-retries. We want to count all these as the
|
||||||
@@ -77,6 +78,11 @@ class AwsSesClient(EmailClient):
|
|||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def ses_inject_connection_header(self, params, **kwargs):
|
||||||
|
# keep underlying TLS connection open, so we do not spend lots of CPU
|
||||||
|
# and network time renegotiating TLS
|
||||||
|
params['headers']['Connection'] = 'Keep-Alive'
|
||||||
|
|
||||||
def send_email(self,
|
def send_email(self,
|
||||||
source,
|
source,
|
||||||
to_addresses,
|
to_addresses,
|
||||||
@@ -148,3 +154,4 @@ def punycode_encode_email(email_address):
|
|||||||
# only the hostname should ever be punycode encoded.
|
# only the hostname should ever be punycode encoded.
|
||||||
local, hostname = email_address.split('@')
|
local, hostname = email_address.split('@')
|
||||||
return '{}@{}'.format(local, hostname.encode('idna').decode('utf-8'))
|
return '{}@{}'.format(local, hostname.encode('idna').decode('utf-8'))
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from time import monotonic
|
from time import monotonic
|
||||||
from requests import request, RequestException
|
from requests import request, RequestException, Session
|
||||||
|
from requests.adapters import HTTPAdapter
|
||||||
|
|
||||||
from app.clients.sms import (SmsClient, SmsClientResponseException)
|
from app.clients.sms import (SmsClient, SmsClientResponseException)
|
||||||
|
|
||||||
@@ -69,6 +70,9 @@ class FiretextClient(SmsClient):
|
|||||||
self.name = 'firetext'
|
self.name = 'firetext'
|
||||||
self.url = current_app.config.get('FIRETEXT_URL')
|
self.url = current_app.config.get('FIRETEXT_URL')
|
||||||
self.statsd_client = statsd_client
|
self.statsd_client = statsd_client
|
||||||
|
# this uses urllib3 under the hood to create a connection pool
|
||||||
|
self.session = Session()
|
||||||
|
self.session.mount('https://', HTTPAdapter(pool_maxsize=32))
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -103,8 +107,7 @@ class FiretextClient(SmsClient):
|
|||||||
response = None
|
response = None
|
||||||
start_time = monotonic()
|
start_time = monotonic()
|
||||||
try:
|
try:
|
||||||
response = request(
|
response = self.session.post(
|
||||||
"POST",
|
|
||||||
self.url,
|
self.url,
|
||||||
data=data,
|
data=data,
|
||||||
timeout=60
|
timeout=60
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
from time import monotonic
|
from time import monotonic
|
||||||
from requests import (request, RequestException)
|
from requests import (request, RequestException, Session)
|
||||||
|
from requests.adapters import HTTPAdapter
|
||||||
|
|
||||||
from app.clients.sms import (SmsClient, SmsClientResponseException)
|
from app.clients.sms import (SmsClient, SmsClientResponseException)
|
||||||
|
|
||||||
mmg_response_map = {
|
mmg_response_map = {
|
||||||
@@ -75,6 +77,9 @@ class MMGClient(SmsClient):
|
|||||||
self.name = 'mmg'
|
self.name = 'mmg'
|
||||||
self.statsd_client = statsd_client
|
self.statsd_client = statsd_client
|
||||||
self.mmg_url = current_app.config.get('MMG_URL')
|
self.mmg_url = current_app.config.get('MMG_URL')
|
||||||
|
# this uses urllib3 under the hood to create a connection pool
|
||||||
|
self.session = Session()
|
||||||
|
self.session.mount('https://', HTTPAdapter(pool_maxsize=32))
|
||||||
|
|
||||||
def record_outcome(self, success, response):
|
def record_outcome(self, success, response):
|
||||||
status_code = response.status_code if response else 503
|
status_code = response.status_code if response else 503
|
||||||
@@ -108,8 +113,8 @@ class MMGClient(SmsClient):
|
|||||||
response = None
|
response = None
|
||||||
start_time = monotonic()
|
start_time = monotonic()
|
||||||
try:
|
try:
|
||||||
response = request(
|
|
||||||
"POST",
|
response = self.session.post(
|
||||||
self.mmg_url,
|
self.mmg_url,
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers={
|
headers={
|
||||||
|
|||||||
@@ -53,6 +53,11 @@
|
|||||||
'notify-delivery-worker-jobs': {},
|
'notify-delivery-worker-jobs': {},
|
||||||
'notify-delivery-worker-research': {},
|
'notify-delivery-worker-research': {},
|
||||||
'notify-delivery-worker-sender': {'disk_quota': '2G', 'memory': '4G'},
|
'notify-delivery-worker-sender': {'disk_quota': '2G', 'memory': '4G'},
|
||||||
|
'notify-delivery-worker-sender-canary': {'disk_quota': '2G', 'memory': '4G', 'instances': {
|
||||||
|
'preview': 0,
|
||||||
|
'staging': 1,
|
||||||
|
'production': 0
|
||||||
|
},},
|
||||||
'notify-delivery-worker-periodic': {},
|
'notify-delivery-worker-periodic': {},
|
||||||
'notify-delivery-worker-reporting': {
|
'notify-delivery-worker-reporting': {
|
||||||
'additional_env_vars': {
|
'additional_env_vars': {
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ case $NOTIFY_APP_NAME in
|
|||||||
exec scripts/run_multi_worker_app_paas.sh celery multi start 3 -c 10 -A run_celery.notify_celery --loglevel=INFO \
|
exec scripts/run_multi_worker_app_paas.sh celery multi start 3 -c 10 -A run_celery.notify_celery --loglevel=INFO \
|
||||||
--logfile=/dev/null --pidfile=/tmp/celery%N.pid -Q send-sms-tasks,send-email-tasks
|
--logfile=/dev/null --pidfile=/tmp/celery%N.pid -Q send-sms-tasks,send-email-tasks
|
||||||
;;
|
;;
|
||||||
|
delivery-worker-sender-canary)
|
||||||
|
exec scripts/run_multi_worker_app_paas.sh celery multi start 3 -c 10 -A run_celery.notify_celery --loglevel=INFO \
|
||||||
|
--logfile=/dev/null --pidfile=/tmp/celery%N.pid -Q send-sms-tasks,send-email-tasks
|
||||||
|
;;
|
||||||
delivery-worker-periodic)
|
delivery-worker-periodic)
|
||||||
exec scripts/run_app_paas.sh celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=2 \
|
exec scripts/run_app_paas.sh celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=2 \
|
||||||
-Q periodic-tasks 2> /dev/null
|
-Q periodic-tasks 2> /dev/null
|
||||||
|
|||||||
Reference in New Issue
Block a user