Skip to content

Commit

Permalink
Forgot a db
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryTraill committed Jul 24, 2024
1 parent 9edcef4 commit d1420a6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: hermes_test
POSTGRES_DB: test_chronos
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis
ports:
- 6379:6379s
- 6379:6379
options: --entrypoint redis-server

env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/chronos_test'
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/test_chronos'

steps:
- uses: actions/checkout@v2
Expand All @@ -46,7 +47,6 @@ jobs:

- name: test
run: |
make reset-db
make test
- name: codecov
Expand Down
4 changes: 2 additions & 2 deletions chronos/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Settings(BaseSettings):

# Postgres
# pg_dsn: PostgresDsn = Field('postgres://postgres@localhost:5432/chronos', validation_alias='DATABASE_URL')
pg_dsn: str = 'postgresql://postgres@localhost:5432/chronos'
test_pg_dsn: str = 'postgresql://postgres@localhost:5432/test_chronos'
pg_dsn: str = 'postgresql://postgres:postgres@localhost:5432/chronos'
test_pg_dsn: str = 'postgresql://postgres:postgres@localhost:5432/test_chronos'

# # Redis
# redis_dsn: RedisDsn = Field('redis://localhost:6399', validation_alias='REDISCLOUD_URL')
Expand Down
2 changes: 1 addition & 1 deletion chronos/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def delete_old_logs_job():
@celery_app.task
def _delete_old_logs_job():
with Session(engine) as db:
statement = select(WebhookLog).where(WebhookLog.timestamp >= datetime.utcnow() - timedelta(days=15))
statement = select(WebhookLog).where(WebhookLog.timestamp > datetime.utcnow() - timedelta(days=15))
results = db.exec(statement).all()

delete_statement = delete(WebhookLog).where(col(WebhookLog.id).in_([whl.id for whl in results]))
Expand Down
9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@

[tool.pytest.ini_options]
addopts = '--tb=native'
filterwarnings = [
'ignore::DeprecationWarning:fastapi_admin.resources*', # Remove when fastapi-admin is updated
'ignore::DeprecationWarning:fastapi.applications.*', # Remove when tortoise is updated
]
filterwarnings = []

[tool.coverage.run]
source = ['app']
source = ['chronos']
branch = true
omit = ['app/main.py']
omit = ['chronos/main.py']

[tool.coverage.report]
precision = 2
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ psycopg2==2.9.9
sentry-sdk==2.11.0
opentelemetry-instrumentation-fastapi==0.46b0
fastapi-utilities==0.2.0
redis==5.0.7
redis==5.0.7
pytest-cov==5.0.0
5 changes: 3 additions & 2 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_delete_old_logs(self, db: Session, client: TestClient, celery_session_w
for i in range(1, 31):
whl = create_webhook_log_from_dft_data(
endpoint_id=ep.id,
timestamp=datetime.now() - timedelta(days=i),
timestamp=datetime.utcnow() - timedelta(days=i),
)
db.add(whl)
db.commit()
Expand All @@ -202,4 +202,5 @@ def test_delete_old_logs(self, db: Session, client: TestClient, celery_session_w

_delete_old_logs_job()
logs = db.exec(select(WebhookLog)).all()
assert len(logs) == 15
# The log from 15 days ago is seconds older than the check and thus doesn't get deleted
assert len(logs) == 16

0 comments on commit d1420a6

Please sign in to comment.