Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Install dependencies
- name: Install dependencies
run: |
pip install poetry
- name: Set poetry python version
# Install uv
- name: Install uv
run: |
poetry env use python${{ matrix.python-version }}
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: poetry install --without=dev
run: uv sync --extra dev
- name: Start PostgreSQL
run: |
cp pgmq_postgres.template.env pgmq_postgres.env
cp pgmq_tests.template.env pgmq_tests.env
make start-db
- name: Run tests and collect coverage
run: poetry run pytest tests --cov=pgmq_sqlalchemy.queue --cov-report=xml -n auto tests
run: uv run pytest tests --cov=pgmq_sqlalchemy.queue --cov-report=xml -n auto tests
continue-on-error: true
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/[email protected]
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,16 @@ jobs:
with:
python-version: "3.10"

- name: Install Poetry
- name: Install uv
run: |
curl -sSL https://install.python-poetry.org | python - -y

- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update Poetry configuration
run: poetry config virtualenvs.create false
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Install dependencies
run: poetry install --sync --no-interaction --without=dev
run: uv sync

- name: Package project
run: poetry build
run: uv build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,8 @@ ipython_config.py
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# poetry - replaced by uv
poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
Expand Down
36 changes: 12 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,41 @@ ENV PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
# poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.3.2 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
# it gets named `.venv`
POETRY_VIRTUALENVS_IN_PROJECT=true \
# do not ask any interactive question
POETRY_NO_INTERACTION=1 \
\
# paths
# this is where our requirements + virtual environment will live
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"


# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
# prepend venv to path
ENV PATH="$VENV_PATH/bin:$PATH"

FROM python-base as builder-base
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
# deps for installing uv
curl \
# deps for building python deps
build-essential

# install poetry - respects $POETRY_VERSION & $POETRY_HOME
# The --mount will mount the buildx cache directory to where
# Poetry and Pip store their cache so that they can re-use it
# install uv
RUN --mount=type=cache,target=/root/.cache \
curl -sSL https://install.python-poetry.org | python3 -
curl -LsSf https://astral.sh/uv/install.sh | sh

ENV PATH="/root/.local/bin:$PATH"

# copy project requirement files here to ensure they will be cached.
WORKDIR $PYSETUP_PATH
COPY poetry.lock pyproject.toml ./
COPY pyproject.toml uv.lock ./

# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
# install runtime deps
RUN --mount=type=cache,target=/root/.cache \
poetry install --with=dev
uv sync --extra dev

FROM python:3.12-slim-bookworm as runtime

ENV POETRY_HOME="/opt/poetry" \
VENV_PATH="/opt/pysetup/.venv"
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
ENV VENV_PATH="/opt/pysetup/.venv"
ENV PATH="$VENV_PATH/bin:$PATH"

COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
COPY ./pgmq_sqlalchemy /pgmq_sqlalchemy_test/pgmq_sqlalchemy
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

install: ## Install dependencies and `ruff` pre-commit hooks
pre-commit install
poetry install --with dev
uv sync --extra dev

build: ## Build the package
poetry build
uv build

test-local: ## Run tests locally
poetry run pytest tests --cov=pgmq_sqlalchemy.queue
uv run pytest tests --cov=pgmq_sqlalchemy.queue


test-docker-rebuild: ## Rebuild the docker image
Expand Down Expand Up @@ -38,10 +38,10 @@ exec-db: ## Enter the database container
docker compose exec pgmq_postgres psql -U postgres -d postgres

doc-build: ## Build the documentation
cd doc && poetry run sphinx-build -nW . _build
cd doc && uv run sphinx-build -nW . _build

doc-serve: doc-clean ## Serve the documentation
cd doc && poetry run sphinx-autobuild -nW . _build
cd doc && uv run sphinx-autobuild -nW . _build

doc-clean: ## Clean the documentation
cd doc && rm -r _build
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
![PyPI - Version](https://img.shields.io/pypi/v/pgmq-sqlalchemy)
[![PyPI - License](https://img.shields.io/pypi/l/pgmq-sqlalchemy.svg)](https://github.com/jason810496/pgmq-sqlalchemy/blob/main/LICENSE)
Expand Down
6 changes: 3 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.. _index:


.. image:: https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json
:target: https://python-poetry.org/
:alt: Poetry
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json
:target: https://github.com/astral-sh/uv
:alt: uv
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:
pgmq_postgres:
container_name: pgmq_postgres
Expand Down
24 changes: 11 additions & 13 deletions pgmq_sqlalchemy/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,14 +814,12 @@ def read_with_poll(
queue_name, vt, qty, max_poll_seconds, poll_interval_ms
)

def _set_vt_sync(
self, queue_name: str, msg_id: int, vt_offset: int
) -> Optional[Message]:
def _set_vt_sync(self, queue_name: str, msg_id: int, vt: int) -> Optional[Message]:
"""Set the visibility timeout for a message."""
with self.session_maker() as session:
row = session.execute(
text("select * from pgmq.set_vt(:queue_name,:msg_id,:vt_offset);"),
{"queue_name": queue_name, "msg_id": msg_id, "vt_offset": vt_offset},
text("select * from pgmq.set_vt(:queue_name,:msg_id,:vt);"),
{"queue_name": queue_name, "msg_id": msg_id, "vt": vt},
).fetchone()
session.commit()
if row is None:
Expand All @@ -831,17 +829,17 @@ def _set_vt_sync(
)

async def _set_vt_async(
self, queue_name: str, msg_id: int, vt_offset: int
self, queue_name: str, msg_id: int, vt: int
) -> Optional[Message]:
"""Set the visibility timeout for a message."""
async with self.session_maker() as session:
row = (
await session.execute(
text("select * from pgmq.set_vt(:queue_name,:msg_id,:vt_offset);"),
text("select * from pgmq.set_vt(:queue_name,:msg_id,:vt);"),
{
"queue_name": queue_name,
"msg_id": msg_id,
"vt_offset": vt_offset,
"vt": vt,
},
)
).fetchone()
Expand All @@ -853,7 +851,7 @@ async def _set_vt_async(
msg_id=row[0], read_ct=row[1], enqueued_at=row[2], vt=row[3], message=row[4]
)

def set_vt(self, queue_name: str, msg_id: int, vt_offset: int) -> Optional[Message]:
def set_vt(self, queue_name: str, msg_id: int, vt: int) -> Optional[Message]:
"""
.. _set_vt_method: ref:`pgmq_sqlalchemy.PGMQueue.set_vt`
.. |set_vt_method| replace:: :py:meth:`~pgmq_sqlalchemy.PGMQueue.set_vt`
Expand All @@ -863,7 +861,7 @@ def set_vt(self, queue_name: str, msg_id: int, vt_offset: int) -> Optional[Messa
Args:
queue_name (str): The name of the queue.
msg_id (int): The message id.
vt_offset (int): The visibility timeout in seconds.
vt (int): The visibility timeout in seconds.

Returns:
|schema_message_class|_ or ``None`` if the message does not exist.
Expand Down Expand Up @@ -906,15 +904,15 @@ def consumer_with_backoff_retry(pgmq_client: PGMQueue, queue_name: str):
pgmq_client.set_vt(
queue_name=query_name,
msg_id=msg.msg_id,
vt_offset=_exp_backoff_retry(msg)
vt=_exp_backoff_retry(msg)
)

"""
if self.is_async:
return self.loop.run_until_complete(
self._set_vt_async(queue_name, msg_id, vt_offset)
self._set_vt_async(queue_name, msg_id, vt)
)
return self._set_vt_sync(queue_name, msg_id, vt_offset)
return self._set_vt_sync(queue_name, msg_id, vt)

def _pop_sync(self, queue_name: str) -> Optional[Message]:
with self.session_maker() as session:
Expand Down
Loading
Loading