PgQueuer 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pgqueuer-0.1.0/.github/workflows/ci.yml +38 -0
- pgqueuer-0.1.0/.github/workflows/linting.yml +46 -0
- pgqueuer-0.1.0/.github/workflows/release.yml +35 -0
- pgqueuer-0.1.0/.gitignore +162 -0
- pgqueuer-0.1.0/LICENSE +21 -0
- pgqueuer-0.1.0/PKG-INFO +140 -0
- pgqueuer-0.1.0/README.md +97 -0
- pgqueuer-0.1.0/docker-compose.yml +13 -0
- pgqueuer-0.1.0/pyproject.toml +94 -0
- pgqueuer-0.1.0/setup.cfg +4 -0
- pgqueuer-0.1.0/src/PgQueuer/__init__.py +0 -0
- pgqueuer-0.1.0/src/PgQueuer/__main__.py +6 -0
- pgqueuer-0.1.0/src/PgQueuer/_version.py +17 -0
- pgqueuer-0.1.0/src/PgQueuer/cli.py +130 -0
- pgqueuer-0.1.0/src/PgQueuer/logconfig.py +7 -0
- pgqueuer-0.1.0/src/PgQueuer/models.py +32 -0
- pgqueuer-0.1.0/src/PgQueuer/py.typed +0 -0
- pgqueuer-0.1.0/src/PgQueuer/qm.py +119 -0
- pgqueuer-0.1.0/src/PgQueuer/queries.py +281 -0
- pgqueuer-0.1.0/src/PgQueuer/tm.py +23 -0
- pgqueuer-0.1.0/src/PgQueuer.egg-info/PKG-INFO +140 -0
- pgqueuer-0.1.0/src/PgQueuer.egg-info/SOURCES.txt +30 -0
- pgqueuer-0.1.0/src/PgQueuer.egg-info/dependency_links.txt +1 -0
- pgqueuer-0.1.0/src/PgQueuer.egg-info/requires.txt +16 -0
- pgqueuer-0.1.0/src/PgQueuer.egg-info/top_level.txt +2 -0
- pgqueuer-0.1.0/src/_version.py +16 -0
- pgqueuer-0.1.0/test/conftest.py +45 -0
- pgqueuer-0.1.0/test/db/Dockerfile +19 -0
- pgqueuer-0.1.0/test/db/init_db.sh +11 -0
- pgqueuer-0.1.0/test/test_qm.py +67 -0
- pgqueuer-0.1.0/test/test_queries.py +102 -0
- pgqueuer-0.1.0/test/test_tm.py +24 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Test PgQueuer
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [main]
|
|
6
|
+
push:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
ci:
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
os: [ubuntu-latest]
|
|
16
|
+
|
|
17
|
+
name: PY ${{ matrix.python-version }} on ${{ matrix.os }}
|
|
18
|
+
runs-on: ${{ matrix.os }}
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v4
|
|
25
|
+
with:
|
|
26
|
+
python-version: ${{ matrix.python-version }}
|
|
27
|
+
|
|
28
|
+
- name: Build custom PostgreSQL Docker image
|
|
29
|
+
run: |
|
|
30
|
+
docker-compose up --build -d pgq
|
|
31
|
+
|
|
32
|
+
- name: Install PgQueuer
|
|
33
|
+
run: |
|
|
34
|
+
pip install pip -U
|
|
35
|
+
pip install .[dev]
|
|
36
|
+
|
|
37
|
+
- name: Full test
|
|
38
|
+
run: pytest -v
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: linting
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
|
|
7
|
+
ruff:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
strategy:
|
|
10
|
+
matrix:
|
|
11
|
+
python-version: ["3.10"]
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- name: Set up python
|
|
15
|
+
uses: actions/setup-python@v4
|
|
16
|
+
- name: Install dev-env.
|
|
17
|
+
run: |
|
|
18
|
+
pip install -U pip
|
|
19
|
+
pip install ".[dev]"
|
|
20
|
+
- name: Ruff check
|
|
21
|
+
if: ${{ always() }}
|
|
22
|
+
run: ruff check .
|
|
23
|
+
- name: Ruff format
|
|
24
|
+
if: ${{ always() }}
|
|
25
|
+
run: ruff format . --check
|
|
26
|
+
|
|
27
|
+
mypy:
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
strategy:
|
|
30
|
+
matrix:
|
|
31
|
+
python-version: ["3.10"]
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v4
|
|
34
|
+
|
|
35
|
+
- name: Set up python
|
|
36
|
+
uses: actions/setup-python@v4
|
|
37
|
+
with:
|
|
38
|
+
python-version: ${{ matrix.python-version }}
|
|
39
|
+
|
|
40
|
+
- name: Install dev-env.
|
|
41
|
+
run: |
|
|
42
|
+
pip install -U pip
|
|
43
|
+
pip install ".[dev]"
|
|
44
|
+
|
|
45
|
+
- name: Mypy
|
|
46
|
+
run: mypy .
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Publish Python distribution to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-and-publish:
|
|
9
|
+
name: Publish Python distribution to PyPI.
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
environment:
|
|
13
|
+
name: release
|
|
14
|
+
url: https://pypi.org/project/PgQueuer/
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
id-token: write
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0 # Ensures tags are also fetched
|
|
23
|
+
|
|
24
|
+
- name: Set up Python 3.10.
|
|
25
|
+
uses: actions/setup-python@v4
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.10"
|
|
28
|
+
|
|
29
|
+
- name: Install release dependencies.
|
|
30
|
+
run: python3 -m pip install build twine setuptools_scm
|
|
31
|
+
|
|
32
|
+
- name: Build package.
|
|
33
|
+
run: python3 -m build . --sdist --wheel --outdir dist/
|
|
34
|
+
|
|
35
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
158
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
159
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
160
|
+
#.idea/
|
|
161
|
+
src/PgQueuer/_version.py
|
|
162
|
+
src/_version.py
|
pgqueuer-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 janbjorge
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pgqueuer-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PgQueuer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: PgQueuer is a Python library leveraging PostgreSQL for efficient job queuing.
|
|
5
|
+
Author: janbjorge
|
|
6
|
+
License: MIT License
|
|
7
|
+
Project-URL: Documentation, https://github.com/janbjorge/PgQueuer/
|
|
8
|
+
Project-URL: Homepage, https://github.com/janbjorge/PgQueuer/
|
|
9
|
+
Project-URL: Issues, https://github.com/janbjorge/PgQueuer/issues
|
|
10
|
+
Project-URL: Repository, https://github.com/janbjorge/PgQueuer/
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Web Environment
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python
|
|
22
|
+
Classifier: Topic :: Database
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Topic :: Utilities
|
|
25
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: asyncpg>=0.27.0
|
|
30
|
+
Requires-Dist: pgcachewatch>=0.4
|
|
31
|
+
Requires-Dist: pydantic>=2.0.0
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: asyncpg-stubs; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy-extensions; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff; extra == "dev"
|
|
39
|
+
Provides-Extra: docs
|
|
40
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
41
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
42
|
+
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
|
43
|
+
|
|
44
|
+
## PgQueuer
|
|
45
|
+
|
|
46
|
+
PgQueuer is a minimalist, high-performance job queue library for Python, leveraging the robustness of PostgreSQL. Designed for simplicity and efficiency, PgQueuer uses PostgreSQL's native features like transactions, row locking, and LISTEN/NOTIFY to manage job queues effortlessly.
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
- **Simple Integration**: Easy to integrate with existing Python applications using PostgreSQL.
|
|
51
|
+
- **Efficient Concurrency Handling**: Utilizes PostgreSQL's `FOR UPDATE SKIP LOCKED` for reliable and concurrent job processing.
|
|
52
|
+
- **Real-time Notifications**: Leverages `LISTEN` and `NOTIFY` for real-time updates on job status changes.
|
|
53
|
+
- **Scalable**: Built to efficiently scale with your application's needs.
|
|
54
|
+
|
|
55
|
+
### Getting Started
|
|
56
|
+
|
|
57
|
+
#### Installation
|
|
58
|
+
|
|
59
|
+
To install PgQueuer, simply run the following command:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install PgQueuer
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This command installs PgQueuer along with its dependencies, setting up everything you need to start integrating it into your application.
|
|
66
|
+
|
|
67
|
+
#### Database Configuration
|
|
68
|
+
|
|
69
|
+
Configure your database connection settings by setting the appropriate environment variables for your PostgreSQL credentials:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
export PGHOST='localhost'
|
|
73
|
+
export PGDATABASE='your_database'
|
|
74
|
+
export PGUSER='your_username'
|
|
75
|
+
export PGPASSWORD='your_password'
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### CLI Usage
|
|
79
|
+
|
|
80
|
+
PgQueuer provides a command-line interface for easy management of installation and uninstallation. Ensure you have configured your environment variables or use the appropriate flags to specify your database credentials.
|
|
81
|
+
|
|
82
|
+
- **Installing PgQueuer Database Components**:
|
|
83
|
+
```bash
|
|
84
|
+
python -m PgQueuer install
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- **Uninstalling PgQueuer Database Components**:
|
|
88
|
+
```bash
|
|
89
|
+
python -m uninstall
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The CLI supports several flags to customize the connection settings. Use `--help` to see all available options.
|
|
93
|
+
|
|
94
|
+
### Use-Case: Processing Incoming Data Messages
|
|
95
|
+
|
|
96
|
+
In this scenario, the system is designed to manage a queue of incoming data messages that need to be processed. Each message is encapsulated as a job, and these jobs are then processed by a designated function linked to an entrypoint. This is typical in systems where large volumes of data are collected continuously, such as telemetry data from IoT devices, logs from web servers, or transaction data in financial systems.
|
|
97
|
+
|
|
98
|
+
#### Function Description:
|
|
99
|
+
The `fetch` function, tied to the `fetch` entrypoint, is responsible for processing each message. It simulates a processing task by printing the content of each message. This function could be adapted to perform more complex operations such as parsing, analyzing, storing, or forwarding the data as required by the application.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
import asyncio
|
|
103
|
+
import time
|
|
104
|
+
|
|
105
|
+
import asyncpg
|
|
106
|
+
|
|
107
|
+
from PgQueuer import qm, queries
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
async def main() -> None:
|
|
111
|
+
# Set up a connection pool with a minimum of 2 connections.
|
|
112
|
+
pool = await asyncpg.create_pool(min_size=2)
|
|
113
|
+
# Initialize the QueueManager with the connection pool and query handler.
|
|
114
|
+
app = qm.QueueManager(
|
|
115
|
+
pool,
|
|
116
|
+
queries.PgQueuerQueries(pool),
|
|
117
|
+
queries.PgQueuerLogQueries(pool),
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Number of messages to simulate.
|
|
121
|
+
N = 10_000
|
|
122
|
+
|
|
123
|
+
# Enqueue messages.
|
|
124
|
+
for n in range(N):
|
|
125
|
+
await app.q.enqueue("fetch", f"this is from me: {n}".encode())
|
|
126
|
+
|
|
127
|
+
# Define a processing function for each message.
|
|
128
|
+
@c.entrypoint("fetch")
|
|
129
|
+
async def process_message(context: bytes) -> None:
|
|
130
|
+
# Simulate parsing the message.
|
|
131
|
+
message = context.decode()
|
|
132
|
+
# Print the message to simulate processing.
|
|
133
|
+
print(f"Processed message: {message}")
|
|
134
|
+
|
|
135
|
+
await app.run()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
asyncio.run(main())
|
|
140
|
+
```
|
pgqueuer-0.1.0/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
## PgQueuer
|
|
2
|
+
|
|
3
|
+
PgQueuer is a minimalist, high-performance job queue library for Python, leveraging the robustness of PostgreSQL. Designed for simplicity and efficiency, PgQueuer uses PostgreSQL's native features like transactions, row locking, and LISTEN/NOTIFY to manage job queues effortlessly.
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- **Simple Integration**: Easy to integrate with existing Python applications using PostgreSQL.
|
|
8
|
+
- **Efficient Concurrency Handling**: Utilizes PostgreSQL's `FOR UPDATE SKIP LOCKED` for reliable and concurrent job processing.
|
|
9
|
+
- **Real-time Notifications**: Leverages `LISTEN` and `NOTIFY` for real-time updates on job status changes.
|
|
10
|
+
- **Scalable**: Built to efficiently scale with your application's needs.
|
|
11
|
+
|
|
12
|
+
### Getting Started
|
|
13
|
+
|
|
14
|
+
#### Installation
|
|
15
|
+
|
|
16
|
+
To install PgQueuer, simply run the following command:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install PgQueuer
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
This command installs PgQueuer along with its dependencies, setting up everything you need to start integrating it into your application.
|
|
23
|
+
|
|
24
|
+
#### Database Configuration
|
|
25
|
+
|
|
26
|
+
Configure your database connection settings by setting the appropriate environment variables for your PostgreSQL credentials:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
export PGHOST='localhost'
|
|
30
|
+
export PGDATABASE='your_database'
|
|
31
|
+
export PGUSER='your_username'
|
|
32
|
+
export PGPASSWORD='your_password'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### CLI Usage
|
|
36
|
+
|
|
37
|
+
PgQueuer provides a command-line interface for easy management of installation and uninstallation. Ensure you have configured your environment variables or use the appropriate flags to specify your database credentials.
|
|
38
|
+
|
|
39
|
+
- **Installing PgQueuer Database Components**:
|
|
40
|
+
```bash
|
|
41
|
+
python -m PgQueuer install
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- **Uninstalling PgQueuer Database Components**:
|
|
45
|
+
```bash
|
|
46
|
+
python -m uninstall
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The CLI supports several flags to customize the connection settings. Use `--help` to see all available options.
|
|
50
|
+
|
|
51
|
+
### Use-Case: Processing Incoming Data Messages
|
|
52
|
+
|
|
53
|
+
In this scenario, the system is designed to manage a queue of incoming data messages that need to be processed. Each message is encapsulated as a job, and these jobs are then processed by a designated function linked to an entrypoint. This is typical in systems where large volumes of data are collected continuously, such as telemetry data from IoT devices, logs from web servers, or transaction data in financial systems.
|
|
54
|
+
|
|
55
|
+
#### Function Description:
|
|
56
|
+
The `fetch` function, tied to the `fetch` entrypoint, is responsible for processing each message. It simulates a processing task by printing the content of each message. This function could be adapted to perform more complex operations such as parsing, analyzing, storing, or forwarding the data as required by the application.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import asyncio
|
|
60
|
+
import time
|
|
61
|
+
|
|
62
|
+
import asyncpg
|
|
63
|
+
|
|
64
|
+
from PgQueuer import qm, queries
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
async def main() -> None:
|
|
68
|
+
# Set up a connection pool with a minimum of 2 connections.
|
|
69
|
+
pool = await asyncpg.create_pool(min_size=2)
|
|
70
|
+
# Initialize the QueueManager with the connection pool and query handler.
|
|
71
|
+
app = qm.QueueManager(
|
|
72
|
+
pool,
|
|
73
|
+
queries.PgQueuerQueries(pool),
|
|
74
|
+
queries.PgQueuerLogQueries(pool),
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# Number of messages to simulate.
|
|
78
|
+
N = 10_000
|
|
79
|
+
|
|
80
|
+
# Enqueue messages.
|
|
81
|
+
for n in range(N):
|
|
82
|
+
await app.q.enqueue("fetch", f"this is from me: {n}".encode())
|
|
83
|
+
|
|
84
|
+
# Define a processing function for each message.
|
|
85
|
+
@c.entrypoint("fetch")
|
|
86
|
+
async def process_message(context: bytes) -> None:
|
|
87
|
+
# Simulate parsing the message.
|
|
88
|
+
message = context.decode()
|
|
89
|
+
# Print the message to simulate processing.
|
|
90
|
+
print(f"Processed message: {message}")
|
|
91
|
+
|
|
92
|
+
await app.run()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
asyncio.run(main())
|
|
97
|
+
```
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "setuptools.build_meta"
|
|
3
|
+
requires = ["pip>=22.0.0", "setuptools", "setuptools_scm", "wheel"]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
authors = [{ name = "janbjorge"}]
|
|
7
|
+
description = "PgQueuer is a Python library leveraging PostgreSQL for efficient job queuing."
|
|
8
|
+
dynamic = ["version"]
|
|
9
|
+
license = { text = "MIT License" }
|
|
10
|
+
name = "PgQueuer"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Environment :: Web Environment",
|
|
17
|
+
"Framework :: AsyncIO",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Natural Language :: English",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python",
|
|
26
|
+
"Topic :: Database",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
"Topic :: Utilities",
|
|
29
|
+
"Topic :: System :: Distributed Computing"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
dependencies = [
|
|
33
|
+
"asyncpg>=0.27.0",
|
|
34
|
+
"pgcachewatch>=0.4",
|
|
35
|
+
"pydantic>=2.0.0",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Documentation = "https://github.com/janbjorge/PgQueuer/"
|
|
40
|
+
Homepage = "https://github.com/janbjorge/PgQueuer/"
|
|
41
|
+
Issues = "https://github.com/janbjorge/PgQueuer/issues"
|
|
42
|
+
Repository = "https://github.com/janbjorge/PgQueuer/"
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
dev = [
|
|
46
|
+
"asyncpg-stubs",
|
|
47
|
+
"mypy-extensions",
|
|
48
|
+
"mypy",
|
|
49
|
+
"pytest-asyncio",
|
|
50
|
+
"pytest",
|
|
51
|
+
"ruff",
|
|
52
|
+
]
|
|
53
|
+
docs = [
|
|
54
|
+
"myst-parser",
|
|
55
|
+
"sphinx",
|
|
56
|
+
"sphinx-rtd-theme",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
[tool.setuptools_scm]
|
|
60
|
+
write_to = "src/_version.py"
|
|
61
|
+
|
|
62
|
+
[tool.ruff]
|
|
63
|
+
line-length = 88
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
select = [
|
|
66
|
+
"C",
|
|
67
|
+
"E",
|
|
68
|
+
"F",
|
|
69
|
+
"I",
|
|
70
|
+
"PIE",
|
|
71
|
+
"Q",
|
|
72
|
+
"RET",
|
|
73
|
+
"RSE",
|
|
74
|
+
"SIM",
|
|
75
|
+
"W",
|
|
76
|
+
"C90",
|
|
77
|
+
]
|
|
78
|
+
[tool.ruff.lint.isort]
|
|
79
|
+
combine-as-imports = true
|
|
80
|
+
|
|
81
|
+
[tool.mypy]
|
|
82
|
+
disallow_untyped_defs = true
|
|
83
|
+
exclude = "^(build|docs)"
|
|
84
|
+
extra_checks = true
|
|
85
|
+
ignore_missing_imports = true
|
|
86
|
+
plugins = ["pydantic.mypy"]
|
|
87
|
+
python_version = "3.10"
|
|
88
|
+
strict_equality = true
|
|
89
|
+
warn_redundant_casts = true
|
|
90
|
+
warn_unused_configs = true
|
|
91
|
+
warn_unused_ignores = true
|
|
92
|
+
|
|
93
|
+
[tool.pytest.ini_options]
|
|
94
|
+
asyncio_mode = "auto"
|
pgqueuer-0.1.0/setup.cfg
ADDED
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# file generated by setuptools_scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
TYPE_CHECKING = False
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from typing import Tuple, Union
|
|
6
|
+
|
|
7
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
8
|
+
else:
|
|
9
|
+
VERSION_TUPLE = object
|
|
10
|
+
|
|
11
|
+
version: str
|
|
12
|
+
__version__: str
|
|
13
|
+
__version_tuple__: VERSION_TUPLE
|
|
14
|
+
version_tuple: VERSION_TUPLE
|
|
15
|
+
|
|
16
|
+
__version__ = version = "0.1.dev1+gac06244.d20240420"
|
|
17
|
+
__version_tuple__ = version_tuple = (0, 1, "dev1", "gac06244.d20240420")
|