Skip to content

Commit

Permalink
Remote patron activity sync celery task (PP-1164) (#1894)
Browse files Browse the repository at this point in the history
This PR updates our Patron API that sync with remote providers to do the sync as an async celery task, rather then in the main web thread worker. To coordinate these patron activity sync tasks, I wired up redis as a service that we can use to store data, not just as a celery broker.

Redis is used to store the state of the patron activity sync and as a distributed lock, so that only one task is doing a sync at a time.
  • Loading branch information
jonathangreen authored Jun 13, 2024
1 parent f372958 commit 1b2ce5f
Show file tree
Hide file tree
Showing 45 changed files with 2,370 additions and 1,305 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ grant all privileges on database circ to palace;

### Redis

Redis is used as the broker for Celery. You can run Redis with docker using the following command:
Redis is used as the broker for Celery and the caching layer. You can run Redis with docker using the following command:

```sh
docker run -d --name redis -p 6379:6379 redis
Expand Down Expand Up @@ -193,6 +193,19 @@ We support overriding a number of other Celery settings via environment variable
the defaults should be sufficient. The full list of settings can be found in
[`service/celery/configuration.py`](src/palace/manager/service/celery/configuration.py).

#### Redis

We use Redis as the caching layer for the application. Although you can use the same redis database for both
Celery and caching, we recommend that you use a separate database for each purpose to avoid conflicts.

- `PALACE_REDIS_URL`: The URL of the Redis instance to use for caching. (**required**).
- for example:
```sh
export PALACE_REDIS_URL="redis://localhost:6379/1"
```
- `PALACE_REDIS_KEY_PREFIX`: The prefix to use for keys stored in the Redis instance. The default is `palace`.
This is useful if you want to use the same Redis database for multiple CM (optional).

#### General

- `PALACE_BASE_URL`: The base URL of the application. Used to create absolute links. (optional)
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ x-cm-variables: &cm
PALACE_CELERY_BROKER_URL: "redis://redis:6379/0"
PALACE_CELERY_BROKER_TRANSPORT_OPTIONS_GLOBAL_KEYPREFIX: "test"
PALACE_CELERY_CLOUDWATCH_STATISTICS_DRYRUN: "true"
PALACE_REDIS_URL: "redis://redis:6379/1"

# Set up the environment variables used for testing as well
PALACE_TEST_DATABASE_URL: "postgresql://palace:test@pg:5432/circ"
PALACE_TEST_SEARCH_URL: "http://os:9200"
PALACE_TEST_MINIO_URL: "http://minio:9000"
PALACE_TEST_MINIO_USER: "palace"
PALACE_TEST_MINIO_PASSWORD: "test123456789"
PALACE_TEST_REDIS_URL: "redis://redis:6379/2"
depends_on:
pg:
condition: service_healthy
Expand Down
27 changes: 20 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ python-dateutil = "2.9.0.post0"
python3-saml = "^1.16" # python-saml is required for SAML authentication
pytz = "^2023.3"
pyyaml = "^6.0"
redis = "^5.0.5"
redmail = "^0.6.0"
requests = "^2.29"
sqlalchemy = {version = "^1.4", extras = ["mypy"]}
Expand Down Expand Up @@ -308,6 +309,7 @@ types-Pillow = "^10.0.0"
types-psycopg2 = "^2.9.21"
types-python-dateutil = "^2.8.19"
types-pytz = "^2024.1"
types-redis = "^4.6.0.20240425"
types-requests = "^2.28.11"

[tool.poetry.group.pg]
Expand Down
Loading

0 comments on commit 1b2ce5f

Please sign in to comment.