diff --git a/backend/__init__.py b/backend/__init__.py index 34878ea6ec..f3ac5cd773 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -38,7 +38,7 @@ def format_url(endpoint): mail = Mail() oauth = OAuth() limiter = Limiter( - storage_uri=EnvironmentConfig.MEMCACHED_URI, + storage_uri=EnvironmentConfig.REDIS_URI, key_func=get_remote_address, headers_enabled=True, ) @@ -134,11 +134,11 @@ def add_api_endpoints(app): "message": "You have exceeded the rate limit. Please try again later.", "status": 429, }, - "MemcacheUnexpectedCloseError": { - "SubCode": "MemcacheUnexpectedCloseError", - "message": "Connection to Memcache server lost.", + "ConnectionError":{ + "SubCode": "RedisConnectionError", + "message": "Connection to Redis server refused.", "status": 500, - }, + } } api = Api(app, errors=rate_limit_error) diff --git a/backend/config.py b/backend/config.py index a6aa86c17f..ab444f5c46 100644 --- a/backend/config.py +++ b/backend/config.py @@ -110,12 +110,12 @@ class EnvironmentConfig: "TM_API_RATE_LIMIT_THRESHOLD", "100 per hour" ) # Memcache configuration - MEMCACHED_PORT = os.getenv("TM_MEMCACHE_PORT", None) - MEMCACHED_HOST = os.getenv("TM_MEMCACHE_HOST", None) - if MEMCACHED_PORT and MEMCACHED_HOST: - MEMCACHED_URI = f"memcached://{MEMCACHED_HOST}:{MEMCACHED_PORT}" + REDIS_PORT = os.getenv("TM_REDIS_PORT", None) + REDIS_HOST = os.getenv("TM_REDIS_HOST", None) + if REDIS_PORT and REDIS_HOST: + REDIS_URI = f"redis://{REDIS_HOST}:{REDIS_PORT}" else: - MEMCACHED_URI = None + REDIS_URI = None # Languages offered by the Tasking Manager # Please note that there must be exactly the same number of Codes as languages. diff --git a/docker-compose.yml b/docker-compose.yml index 1032c4b914..be12439422 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,9 @@ services: <<: *backend container_name: backend restart: always + depends_on: + - postgresql + - redis labels: - traefik.http.routers.backend.rule=Host(`localhost`) && PathPrefix(`/api/`) - traefik.http.services.backend.loadbalancer.server.port=5000 @@ -43,7 +46,14 @@ services: env_file: ${ENV_FILE:-tasking-manager.env} networks: - tm-web - + redis: + image: bitnami/redis:7.0.4 + container_name: redis + environment: + - ALLOW_EMPTY_PASSWORD=yes + restart: always + networks: + - tm-web traefik: image: traefik:v2.3 restart: always diff --git a/requirements.txt b/requirements.txt index 501ca716d2..3f338edd24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,7 +36,7 @@ Mako==1.1.3 markdown==3.3.3 MarkupSafe==1.1.1 mccabe==0.6.1 -pymemcache==3.5.2 +redis==3.5.0 newrelic==5.22.1.152 nose==1.3.7 oauthlib==2.0.2