Skip to content

Commit

Permalink
feat: SB-788 SB-791 Updated python in workers from version 3.8 to 3.9…
Browse files Browse the repository at this point in the history
…. Updated all workers packages (SQLAlchemy 1.4 -> 2.0 included).

Approved-by: Michał Kleszcz
  • Loading branch information
kailip committed Jan 30, 2023
1 parent 8a16634 commit 0c5aca0
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 267 deletions.
8 changes: 4 additions & 4 deletions packages/workers/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BASE_IMAGE=python:3.8-slim-buster
ARG BASE_IMAGE=python:3.9-slim-bullseye
FROM ${BASE_IMAGE}

ENV APP_PATH=/app
Expand All @@ -14,7 +14,7 @@ RUN \
wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
apt-get update && \
apt-get install -yqq nodejs && \
pip install -U pip==21.3.1 && pip install pdm==2.1.1 && \
pip install -U pip==22.3.1 && pip install pdm==2.4.1 && \
npm i -g npm@^8 nx@^15.4.5 pnpm@^7.25.0 && \
rm -rf /var/lib/apt/lists/*

Expand All @@ -33,8 +33,8 @@ COPY $SRC_CORE_PATH $DEST_CORE_PATH/
COPY $SRC_WORKERS_PATH $DEST_WORKERS_PATH/
RUN chmod +x $DEST_WORKERS_PATH/scripts/*.sh

ENV PYTHONPATH=/pkgs/__pypackages__/3.8/lib \
PATH=$PATH:/pkgs/__pypackages__/3.8/bin
ENV PYTHONPATH=/pkgs/__pypackages__/3.9/lib \
PATH=$PATH:/pkgs/__pypackages__/3.9/bin

WORKDIR $DEST_WORKERS_PATH

Expand Down
6 changes: 3 additions & 3 deletions packages/workers/content/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_create_item_db_instance(self, contentful_sync, db_session, entry_factor

contentful_sync.sync()

entry_instance = db_session.query(MockContentfulItem).get(entry_id)
entry_instance = db_session.get(MockContentfulItem, entry_id)
assert entry_instance.fields == entry.fields()
assert entry_instance.is_published

Expand All @@ -58,8 +58,8 @@ def test_unknown_items_marked_as_unpublished(self, contentful_sync, db_session:

contentful_sync.sync()

old_entry_instance = db_session.query(MockContentfulItem).get(old_entry_id)
old_entry_instance = db_session.get(MockContentfulItem, old_entry_id)
assert not old_entry_instance.is_published

entry_instance = db_session.query(MockContentfulItem).get(entry_id)
entry_instance = db_session.get(MockContentfulItem, entry_id)
assert entry_instance.is_published
3 changes: 0 additions & 3 deletions packages/workers/dao/db/connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from sqlalchemy import MetaData
from sqlalchemy import create_engine
from sqlalchemy.engine import url

import settings

db_url = None
db = None
meta = None

if settings.DB_CONNECTION is not None:
db_url = url.URL.create(
Expand All @@ -21,4 +19,3 @@
)

db = create_engine(db_url)
meta = MetaData(db)
2 changes: 1 addition & 1 deletion packages/workers/dao/db/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import declarative_base

Base = declarative_base()
451 changes: 220 additions & 231 deletions packages/workers/pdm.lock

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions packages/workers/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
line-length = 120
skip-string-normalization = true
exclude = "/(.git|.serverless|node_modules|data)/"
target-versions = "py38"
target-versions = "py39"


[tool.pdm]
Expand All @@ -13,15 +13,15 @@ verify_ssl = true

[tool.pdm.dev-dependencies]
dev = [
"black==22.3.0",
"flake8~=4.0",
"moto~=3.1",
"pytest~=7.1",
"pytest-mock~=3.7",
"pytest-factoryboy~=2.3",
"black~=22.12",
"flake8~=6.0",
"moto~=4.1",
"pytest~=7.2",
"pytest-mock~=3.10",
"pytest-factoryboy~=2.5",
"pytest-dotenv~=0.5",
"python-dotenv~=0.20",
"pytest-cov>=4.0.0",
"python-dotenv~=0.21",
"pytest-cov~=4.0",
]
[project]
name = ""
Expand All @@ -31,16 +31,16 @@ authors = [
{name = "", email = ""},
]
dependencies = [
"boto3~=1.23",
"pyjwt~=2.4",
"boto3~=1.26",
"pyjwt~=2.6",
"hashids~=1.3",
"contentful~=1.13",
"environs~=9.5",
"psycopg2-binary~=2.9",
"sentry-sdk~=1.5",
"sqlalchemy==1.4.36",
"sentry-sdk~=1.14",
"sqlalchemy~=2.0",
]
requires-python = "~=3.8.0"
requires-python = "~=3.9.0"
license = {text = "MIT"}

[project.urls]
Expand Down
12 changes: 6 additions & 6 deletions packages/workers/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ provider:
functions:
ScheduleTask:
handler: scheduler.handlers.schedule_task
runtime: python3.8
runtime: python3.9
timeout: 20
memorySize: 128
environment: ${file(./${self:custom.confFile.${self:provider.stage}}):ScheduleTask.environment}
Expand All @@ -30,7 +30,7 @@ functions:

ExecuteScheduledTask:
handler: scheduler.handlers.execute_task
runtime: python3.8
runtime: python3.9
timeout: 6
memorySize: 128
environment: ${file(./${self:custom.confFile.${self:provider.stage}}):ExecuteScheduledTask.environment}
Expand All @@ -49,7 +49,7 @@ functions:

SynchronizeContentfulContent:
handler: content.handlers.synchronize_content
runtime: python3.8
runtime: python3.9
timeout: 30
memorySize: 256
environment: ${file(./${self:custom.confFile.${self:provider.stage}}):SynchronizeContentfulContent.environment}
Expand All @@ -64,7 +64,7 @@ functions:

WebSocketsConnectHandler:
handler: websockets.handlers.connect.handle
runtime: python3.8
runtime: python3.9
timeout: 30
memorySize: 256
environment: ${file(./${self:custom.confFile.${self:provider.stage}}):WebSocketsHandler.environment}
Expand All @@ -74,7 +74,7 @@ functions:

WebSocketsMessageHandler:
handler: websockets.handlers.message.handle
runtime: python3.8
runtime: python3.9
timeout: 30
memorySize: 256
environment: ${file(./${self:custom.confFile.${self:provider.stage}}):WebSocketsHandler.environment}
Expand All @@ -84,7 +84,7 @@ functions:

WebSocketsDisconnectHandler:
handler: websockets.handlers.disconnect.handle
runtime: python3.8
runtime: python3.9
timeout: 30
memorySize: 256
environment: ${file(./${self:custom.confFile.${self:provider.stage}}):WebSocketsHandler.environment}
Expand Down
11 changes: 6 additions & 5 deletions packages/workers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dotenv import load_dotenv
from environs import Env
from sqlalchemy import create_engine, exc
from sqlalchemy import text
from sqlalchemy.engine import url


Expand All @@ -27,17 +28,17 @@ def create_test_database():
conn = template_engine.connect()

conn = conn.execution_options(autocommit=False)
conn.execute("ROLLBACK")
conn.execute(text("ROLLBACK"))
try:
conn.execute(f"DROP DATABASE {DB_CONNECTION['dbname']}")
conn.execute(text(f"DROP DATABASE {DB_CONNECTION['dbname']}"))
except exc.ProgrammingError:
# Could not drop the database, probably does not exist
conn.execute("ROLLBACK")
conn.execute(text("ROLLBACK"))
except exc.OperationalError:
# Could not drop database because it's being accessed by other users (psql prompt open?)
conn.execute("ROLLBACK")
conn.execute(text("ROLLBACK"))

conn.execute(f"CREATE DATABASE {DB_CONNECTION['dbname']}")
conn.execute(text(f"CREATE DATABASE {DB_CONNECTION['dbname']}"))
conn.close()

template_engine.dispose()
Expand Down

0 comments on commit 0c5aca0

Please sign in to comment.