Skip to content

Commit

Permalink
Merge pull request #1872 from cisagov/dk/1770-database-cache
Browse files Browse the repository at this point in the history
Issue #1770: dbcache and multiple gunicorn workers
  • Loading branch information
dave-kennedy-ecs authored Mar 7, 2024
2 parents a4568a8 + 83800b6 commit 0acc87c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/createcachetable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow can be run from the CLI for any environment
# gh workflow run createcachetable.yaml -f environment=ENVIRONMENT
# OR
# cf run-task getgov-ENVIRONMENT --command 'python manage.py createcachetable' --name createcachetable

name: Create cache table
run-name: Create cache table for ${{ github.event.inputs.environment }}

on:
workflow_dispatch:
inputs:
environment:
type: choice
description: Which environment should we create cache table for?
options:
- stable
- staging
- development
- backup
- ky
- es
- nl
- rh
- za
- gd
- rb
- ko
- ab
- rjm
- dk

jobs:
createcachetable:
runs-on: ubuntu-latest
env:
CF_USERNAME: CF_${{ github.event.inputs.environment }}_USERNAME
CF_PASSWORD: CF_${{ github.event.inputs.environment }}_PASSWORD
steps:
- name: Create cache table for ${{ github.event.inputs.environment }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets[env.CF_USERNAME] }}
cf_password: ${{ secrets[env.CF_PASSWORD] }}
cf_org: cisa-dotgov
cf_space: ${{ github.event.inputs.environment }}
cf_command: "run-task getgov-${{ github.event.inputs.environment }} --command 'python manage.py createcachetable' --name createcachetable"
3 changes: 3 additions & 0 deletions ops/scripts/create_dev_sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ cd src/
cd ..
cf push getgov-$1 -f ops/manifests/manifest-$1.yaml

echo "Creating cache table..."
cf run-task getgov-$1 --command 'python manage.py createcachetable' --name createcachetable

read -p "Please provide the email of the space developer: " -r
cf set-space-role $REPLY cisa-dotgov $1 SpaceDeveloper

Expand Down
1 change: 1 addition & 0 deletions src/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ services:
command: >
bash -c " python manage.py migrate &&
python manage.py load &&
python manage.py createcachetable &&
python manage.py runserver 0.0.0.0:8080"
db:
Expand Down
15 changes: 6 additions & 9 deletions src/registrar/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,12 @@
# https://docs.djangoproject.com/en/4.0/howto/static-files/


# Caching is disabled by default.
# For a low to medium traffic site, caching causes more
# problems than it solves. Should caching be desired,
# a reasonable start might be:
# CACHES = {
# "default": {
# "BACKEND": "django.core.cache.backends.db.DatabaseCache",
# }
# }
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
"LOCATION": "cache_table",
}
}

# Absolute path to the directory where `collectstatic`
# will place static files for deployment.
Expand Down
2 changes: 1 addition & 1 deletion src/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -o pipefail
# Make sure that django's `collectstatic` has been run locally before pushing up to any environment,
# so that the styles and static assets to show up correctly on any environment.

gunicorn --worker-class=gevent registrar.config.wsgi -t 60
gunicorn --workers=3 --worker-class=gevent registrar.config.wsgi -t 60

0 comments on commit 0acc87c

Please sign in to comment.