Skip to content

Commit

Permalink
Merge branch 'main' into email-deliver-queues
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Oct 24, 2023
2 parents db6a1e6 + 86be8bc commit 722c5c6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
5 changes: 5 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,15 @@ class Scratch(Production):
NOTIFY_ENVIRONMENT = "scratch"


class Dev(Production):
NOTIFY_ENVIRONMENT = "dev"


configs = {
"development": Development,
"test": Test,
"production": Production,
"staging": Staging,
"scratch": Scratch,
"dev": Dev,
}
2 changes: 1 addition & 1 deletion gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
bind = "0.0.0.0:{}".format(os.getenv("PORT"))
accesslog = "-"

on_aws = os.environ.get("NOTIFY_ENVIRONMENT", "") in ["production", "staging", "scratch"]
on_aws = os.environ.get("NOTIFY_ENVIRONMENT", "") in ["production", "staging", "scratch", "dev"]
if on_aws:
# To avoid load balancers reporting errors on shutdown instances, see AWS doc
# > We also recommend that you configure the idle timeout of your application
Expand Down
34 changes: 34 additions & 0 deletions migrations/versions/0439_add_index_n_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Revision ID: 0439_add_index_n_history
Revises: 0438_sms_templates_msgs_left
Create Date: 2023-10-05 00:00:00
"""
from datetime import datetime

from alembic import op

revision = "0439_add_index_n_history"
down_revision = "0438_sms_templates_msgs_left"


def index_exists(name):
connection = op.get_bind()
result = connection.execute(
"SELECT exists(SELECT 1 from pg_indexes where indexname = '{}') as ix_exists;".format(name)
).first()
return result.ix_exists


# option 1
def upgrade():
op.execute("COMMIT")
if not index_exists("ix_notification_history_created_by_id"):
op.create_index(
op.f("ix_notification_history_created_by_id"), "notification_history", ["created_by_id"], postgresql_concurrently=True
)


def downgrade():
op.drop_index(op.f("ix_notification_history_created_by_id"), table_name="notification_history")
3 changes: 3 additions & 0 deletions newrelic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,7 @@ error_collector.ignore_errors = app.v2.errors:BadRequestError jsonschema.excepti
[newrelic:scratch]
# monitor_mode = false

[newrelic:dev]
# monitor_mode = false

# ---------------------------------------------------------------------------
18 changes: 9 additions & 9 deletions scripts/run_celery_exit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function send_signal_to_celery_processes {
# refresh pids to account for the case that some workers may have terminated but others not
get_celery_pids
# send signal to all remaining apps
echo ${APP_PIDS} | tr -d '\n' | tr -s ' ' | xargs echo "Sending signal ${1} to processes with pids: " > /dev/stderr
echo "We will send ${1} signal" > /dev/stderr
echo ${APP_PIDS} | tr -d '\n' | tr -s ' ' | xargs echo "Sending signal ${1} to processes with pids: " >> /proc/1/fd/1
echo "We will send ${1} signal" >> /proc/1/fd/1
for value in ${APP_PIDS}
do
echo kill -s ${1} $value
Expand All @@ -30,14 +30,14 @@ function send_signal_to_celery_processes {

function error_exit()
{
echo "Error: $1" > /dev/stderr
echo "Error: $1" >> /proc/1/fd/1
}

function ensure_celery_is_running {
if [ "${APP_PIDS}" = "" ]; then
echo "There are no celery processes running, this container is bad" > /dev/stderr
echo "There are no celery processes running, this container is bad" >> /proc/1/fd/1

echo "Exporting CF information for diagnosis" > /dev/stderr
echo "Exporting CF information for diagnosis" >> /proc/1/fd/1

env | grep CF

Expand All @@ -49,24 +49,24 @@ function ensure_celery_is_running {
function on_exit {
apk add --no-cache procps
apk add --no-cache coreutils
echo "multi worker app exiting"
echo "multi worker app exiting" >> /proc/1/fd/1
wait_time=0

send_signal_to_celery_processes TERM

# check if the apps are still running every second
while [[ "$wait_time" -le "$TERMINATE_TIMEOUT" ]]; do
echo "exit function is running with wait time of 9s" > /dev/stderr
echo "exit function is running with wait time of 9s" >> /proc/1/fd/1
get_celery_pids
ensure_celery_is_running
let wait_time=wait_time+1
sleep 1
done

echo "sending signal to celery to kill process as TERM signal has not timed out" > /dev/stderr
echo "sending signal to celery to kill process as TERM signal has not timed out" >> /proc/1/fd/1
send_signal_to_celery_processes KILL
}

echo "Run script pid: $$"
echo "Run script pid: $$" >> /proc/1/fd/1

on_exit

0 comments on commit 722c5c6

Please sign in to comment.