2018-02-06 15:12:12 +00:00
|
|
|
import os
|
2023-12-08 21:43:52 -05:00
|
|
|
import socket
|
2017-09-22 15:34:43 +01:00
|
|
|
import sys
|
|
|
|
|
import traceback
|
|
|
|
|
|
2023-12-08 21:43:52 -05:00
|
|
|
import eventlet
|
|
|
|
|
import gunicorn
|
2020-04-20 15:59:47 +01:00
|
|
|
|
2018-03-29 14:57:19 +01:00
|
|
|
workers = 4
|
2018-02-06 15:12:12 +00:00
|
|
|
worker_class = "eventlet"
|
|
|
|
|
worker_connections = 256
|
|
|
|
|
bind = "0.0.0.0:{}".format(os.getenv("PORT"))
|
2019-06-07 15:33:26 +01:00
|
|
|
statsd_host = "{}:8125".format(os.getenv("STATSD_HOST"))
|
2023-08-29 14:54:30 -07:00
|
|
|
gunicorn.SERVER_SOFTWARE = "None"
|
2018-02-06 15:12:12 +00:00
|
|
|
|
2017-09-22 15:34:43 +01:00
|
|
|
|
2017-10-12 11:38:01 +01:00
|
|
|
def on_starting(server):
|
|
|
|
|
server.log.info("Starting Notifications API")
|
|
|
|
|
|
|
|
|
|
|
2017-09-22 15:03:45 +01:00
|
|
|
def worker_abort(worker):
|
2017-10-12 11:38:01 +01:00
|
|
|
worker.log.info("worker received ABORT {}".format(worker.pid))
|
2020-12-22 15:46:31 +00:00
|
|
|
for _threadId, stack in sys._current_frames().items():
|
2023-08-29 14:54:30 -07:00
|
|
|
worker.log.error("".join(traceback.format_stack(stack)))
|
2017-10-12 11:38:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_exit(server):
|
|
|
|
|
server.log.info("Stopping Notifications API")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def worker_int(worker):
|
|
|
|
|
worker.log.info("worker: received SIGINT {}".format(worker.pid))
|
2022-02-23 13:06:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def fix_ssl_monkeypatching():
|
|
|
|
|
"""
|
|
|
|
|
eventlet works by monkey-patching core IO libraries (such as ssl) to be non-blocking. However, there's currently
|
|
|
|
|
a bug: In the normal socket library it may throw a timeout error as a `socket.timeout` exception. However
|
|
|
|
|
eventlet.green.ssl's patch raises an ssl.SSLError('timed out',) instead. redispy handles socket.timeout but not
|
|
|
|
|
ssl.SSLError, so we solve this by monkey patching the monkey patching code to raise the correct exception type
|
|
|
|
|
:scream:
|
|
|
|
|
|
|
|
|
|
https://github.com/eventlet/eventlet/issues/692
|
|
|
|
|
"""
|
|
|
|
|
# this has probably already been called somewhere in gunicorn internals, however, to be sure, we invoke it again.
|
|
|
|
|
# eventlet.monkey_patch can be called multiple times without issue
|
|
|
|
|
eventlet.monkey_patch()
|
|
|
|
|
eventlet.green.ssl.timeout_exc = socket.timeout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fix_ssl_monkeypatching()
|