Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 update #1181

Merged
merged 84 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
059ff72
chore(deps): update all dependencies
renovate[bot] Aug 3, 2024
eb611f4
chore(deps): update all dependencies
renovate[bot] Aug 3, 2024
df94e52
Merge pull request #1142 from procrastinate-org/renovate/all
renovate[bot] Aug 3, 2024
0711988
Merge pull request #1143 from procrastinate-org/renovate/major-all
renovate[bot] Aug 3, 2024
58d121a
chore(deps): lock file maintenance
renovate[bot] Aug 5, 2024
3001234
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 5, 2024
77bf645
Merge pull request #1144 from procrastinate-org/renovate/lock-file-ma…
renovate[bot] Aug 5, 2024
296f0a7
feat: add cancelled and aborted jobs to delete_old_jobs
katlyn Aug 7, 2024
1b5a651
test: add cancelled and aborted jobs to remove_old_jobs
katlyn Aug 7, 2024
9970d03
docs: add removing cancelled and aborted jobs to example
katlyn Aug 7, 2024
97dc67a
chore(deps): update dependency django to v4.2.15 [security]
renovate[bot] Aug 7, 2024
ff9d24a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2024
af6131b
Merge pull request #1148 from procrastinate-org/renovate/pypi-django-…
renovate[bot] Aug 7, 2024
821db68
Merge pull request #1146 from katlyn/feat/clean-cancelled-aborted-jobs
ewjoachim Aug 8, 2024
ba1060d
Make django Admin interface support slightly better UX wise
ticosax Aug 1, 2024
e260037
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2024
6086a96
Move summary.html to procrastinate/admin/summary.html to avoid shadowing
ewjoachim Aug 8, 2024
de8593c
Continue improving the admin with small details
ewjoachim Aug 8, 2024
97f6248
Add __str__ to procrastinate models to improve appearance in the admi…
ewjoachim Aug 8, 2024
7a6c2a4
Ensure the admin status emojis won't get out of sync with real statuses
ewjoachim Aug 8, 2024
ed99be3
Add __str__ for events too
ewjoachim Aug 8, 2024
112f2c8
Merge pull request #1140 from ticosax/admin-filters
ewjoachim Aug 9, 2024
dd45b80
chore(deps): update all dependencies
renovate[bot] Aug 10, 2024
5153f86
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 10, 2024
6500165
Merge pull request #1151 from procrastinate-org/renovate/all
renovate[bot] Aug 10, 2024
b2d40a0
Add sphinx extension
ewjoachim Aug 10, 2024
b8e4869
Document the new extension
ewjoachim Aug 10, 2024
98e02c2
Drink our own champagne: use our new extension
ewjoachim Aug 10, 2024
cbb58fb
Add docstrings to tasks in the demo so that autodoc considers them
ewjoachim Aug 10, 2024
31eb95b
Add integration test
ewjoachim Aug 10, 2024
af31ab3
Poetry lock
ewjoachim Aug 10, 2024
2d23861
Add doc to toctree
ewjoachim Aug 10, 2024
1b8b33a
define pytest_plugins in the top-level conftest
ewjoachim Aug 10, 2024
4633dce
Update procrastinate_demos/demo_async/tasks.py
ewjoachim Aug 11, 2024
86ea2a2
Update tests/conftest.py
ewjoachim Aug 11, 2024
e28d38c
Merge pull request #1152 from procrastinate-org/sphinx-autodoc
ewjoachim Aug 11, 2024
c789eef
chore(deps): lock file maintenance
renovate[bot] Aug 12, 2024
e5197a9
Merge pull request #1155 from procrastinate-org/renovate/lock-file-ma…
renovate[bot] Aug 12, 2024
6521243
Run sync task in its own thread
medihack Aug 15, 2024
3629782
Merge pull request #1160 from openradx/threaded-sync-task-main
ewjoachim Aug 15, 2024
52947ec
Wrap Django exceptions correctly
ewjoachim Aug 15, 2024
fee2e94
Seems we now need setuptools everywhere. I don't get it.
ewjoachim Aug 15, 2024
7f69c10
Merge pull request #1162 from procrastinate-org/wrap-django-errors
ewjoachim Aug 15, 2024
ec499de
Add Kai Schlamp as an author
ewjoachim Aug 15, 2024
a90ae21
Merge pull request #1163 from procrastinate-org/authors
ewjoachim Aug 16, 2024
0e06385
Update licence
ewjoachim Aug 16, 2024
6b39bac
Remove sphinx-autodoc-typehints, upgrade Myst & Sphinx
ewjoachim Aug 11, 2024
ab995ef
Fix docstrings
ewjoachim Aug 11, 2024
54b2382
Fix autodoc configuration
ewjoachim Aug 11, 2024
a80e025
Fix reference doc
ewjoachim Aug 11, 2024
52962b6
Don't install docs dependencies in CI, and run pyright with more rece…
ewjoachim Aug 11, 2024
4392aab
Shenanigans to set Sphinx version
ewjoachim Aug 16, 2024
267311a
Poetry is not ready to support both Sphinx v8 for py3.10 and v7 for p…
ewjoachim Aug 16, 2024
ea08fb3
Include all extras in tests
ewjoachim Aug 16, 2024
643a9ec
Remove extraneous "poetry env use": actions/setup-python@v5 does it
ewjoachim Aug 16, 2024
cfe0aa6
Merge pull request #1153 from procrastinate-org/sphinx-update
ewjoachim Aug 16, 2024
66ac98e
Fix Django + cron using the wrong connector
ewjoachim Aug 16, 2024
6c9bb65
chore(deps): update all dependencies
renovate[bot] Aug 17, 2024
4220c99
Merge pull request #1165 from procrastinate-org/renovate/all
renovate[bot] Aug 17, 2024
a0b8b43
chore(deps): lock file maintenance
renovate[bot] Aug 19, 2024
fae19f8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2024
784a0f7
Merge pull request #1167 from procrastinate-org/renovate/lock-file-ma…
renovate[bot] Aug 19, 2024
0bed3ef
Merge pull request #1164 from procrastinate-org/cron-django
medihack Aug 19, 2024
26b60e6
chore(deps): update all dependencies
renovate[bot] Aug 24, 2024
1ba4a43
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2024
e2bd0dd
chore(deps): update all dependencies
renovate[bot] Aug 24, 2024
21d52db
Merge pull request #1171 from procrastinate-org/renovate/major-all
renovate[bot] Aug 24, 2024
cff0003
Merge pull request #1170 from procrastinate-org/renovate/all
renovate[bot] Aug 24, 2024
1a460ac
chore(deps): lock file maintenance
renovate[bot] Aug 26, 2024
fde4eff
Merge pull request #1173 from procrastinate-org/renovate/lock-file-ma…
renovate[bot] Aug 26, 2024
96d9599
Show how to add async tasks in docs
medihack Aug 27, 2024
46e81e6
Show how to defer tasks in an async way in docs
medihack Aug 27, 2024
004c660
Merge pull request #1174 from openradx/improve-task-and-defer-docs
medihack Aug 27, 2024
9f4adf1
chore(deps): update all dependencies
renovate[bot] Aug 31, 2024
c4ddb39
chore(deps): update all dependencies
renovate[bot] Aug 31, 2024
7287208
Merge pull request #1175 from procrastinate-org/renovate/all
renovate[bot] Aug 31, 2024
6e7bdf8
Merge pull request #1176 from procrastinate-org/renovate/major-all
renovate[bot] Aug 31, 2024
64c57a7
chore(deps): lock file maintenance
renovate[bot] Sep 2, 2024
489d734
Merge pull request #1177 from procrastinate-org/renovate/lock-file-ma…
renovate[bot] Sep 2, 2024
58eeca2
Update ci.yml
ewjoachim Sep 4, 2024
787aa3b
Merge pull request #1179 from procrastinate-org/ewjoachim-patch-1
ewjoachim Sep 4, 2024
4e9840b
Merge branch 'main' into v3
ewjoachim Sep 5, 2024
2d9d5b3
Fix dev-env: use docker compose instead of docker-compose
ewjoachim Sep 5, 2024
657941e
tentative: fix test
ewjoachim Sep 5, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
with:
name: coverage-${{ matrix.python-version }}
path: .coverage.${{ matrix.python-version }}
include-hidden-files: true

static-typing:
name: Run Pyright
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
- id: trailing-whitespace
- id: mixed-line-ending
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.376
rev: v1.1.378
hooks:
- id: pyright
additional_dependencies:
Expand All @@ -40,16 +40,16 @@ repos:
- contextlib2==21.6.0
- croniter==3.0.3
- django-stubs==5.0.4
- django==4.2.15
- importlib-resources==6.4.2
- django==4.2.16
- importlib-resources==6.4.4
- psycopg2-binary==2.9.9
- psycopg[pool]==3.2.1
- python-dateutil==2.9.0.post0
- sphinx==7.1.2
- sqlalchemy==2.0.32
- sqlalchemy==2.0.34
- typing-extensions==4.12.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
rev: v0.6.4
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
Expand Down
45 changes: 22 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Of course, feel free to read the script before launching it.
This script is intended to be a one-liner that sets up everything you need. It makes
the following assumptions:

- You're using `MacOS` or `Linux`, and `bash` or `zsh`.
- You already have `python3` available
- You have `poetry` [installed](https://python-poetry.org/docs/#installation)
- Either you've already setup a PostgreSQL database and environment variables (`PG*`)
are set or you have `docker-compose` available and port 5432 is free.
- Either `psql` and other `libpq` executables are available in the `PATH` or they
are located in `usr/local/opt/libpq/bin` (`Homebrew`).
- You're using `MacOS` or `Linux`, and `bash` or `zsh`.
- You already have `python3` available
- You have `poetry` [installed](https://python-poetry.org/docs/#installation)
- Either you've already setup a PostgreSQL database and environment variables (`PG*`)
are set or you have `docker compose` available and port 5432 is free.
- Either `psql` and other `libpq` executables are available in the `PATH` or they
are located in `usr/local/opt/libpq/bin` (`Homebrew`).

The `dev-env` script will add the `scripts` folder to your `$PATH` for the current
shell, so in the following documentation, if you see `scripts/foo`, you're welcome
Expand All @@ -46,7 +46,7 @@ The PostgreSQL database we used is a fresh standard out-of-the-box database
on the latest stable version.

```console
$ docker-compose up -d postgres
$ docker compose up -d postgres
```

If you want to try out the project locally, it's useful to have `postgresql-client`
Expand Down Expand Up @@ -129,7 +129,6 @@ In addition, an [editorconfig] file will help your favorite editor to respect
procrastinate coding style. It is automatically used by most famous IDEs, such as
Pycharm and VS Code.


### Write the documentation

The documentation is written in `Markdown` and built with `Sphinx` and `MyST`.
Expand Down Expand Up @@ -301,23 +300,23 @@ Python environment on the host system. Alternatively, they can be installed in a
image, and Procrastinate and all the development tools can be run in Docker containers.
Docker is useful when you can't, or don't want to, install system requirements.

This section shows, through `docker-compose` command examples, how to test and run
This section shows, through `docker compose` command examples, how to test and run
Procrastinate in Docker.

Build the `procrastinate` Docker image:

```console
$ export UID GID
$ docker-compose build procrastinate
$ docker compose build procrastinate
```

Run the automated tests:

```console
$ docker-compose run --rm procrastinate pytest
$ docker compose run --rm procrastinate pytest
```

Docker Compose is configured (in `docker-compose.yml`) to mount the local directory on
Docker Compose is configured (in `docker compose.yml`) to mount the local directory on
the host system onto `/src` in the container. This means that local
changes made to the Procrastinate code are visible in Procrastinate containers.

Expand All @@ -326,63 +325,63 @@ container to be run with the current user id and group id. If not set or exporte
Procrastinate container will run as root, and files owned by root may be created in the
developer's working directory.

In the definition of the `procrastinate` service in `docker-compose.yml` the
In the definition of the `procrastinate` service in `docker compose.yml` the
`PROCRASTINATE_APP` variable is set to `procrastinate_demo.app.app` (the
Procrastinate demo application). So `procrastinate` commands run in Procrastinate
containers are always run as if they were passed `--app procrastinate_demo.app.app`.

Run the `procrastinate` command :

```console
$ docker-compose run --rm procrastinate procrastinate -h
$ docker compose run --rm procrastinate procrastinate -h
```

Apply the Procrastinate database schema:

```console
$ docker-compose run --rm procrastinate procrastinate schema --apply
$ docker compose run --rm procrastinate procrastinate schema --apply
```

Run the Procrastinate healthchecks:

```console
$ docker-compose run --rm procrastinate procrastinate healthchecks
$ docker compose run --rm procrastinate procrastinate healthchecks
```

Start a Procrastinate worker (`-d` used to start the container in detached mode):

```console
$ docker-compose up -d procrastinate
$ docker compose up -d procrastinate
```

Run a command (`bash` here) in the Procrastinate worker container just started:

```console
$ docker-compose exec procrastinate bash
$ docker compose exec procrastinate bash
```

Watch the Procrastinate worker logs:

```console
$ docker-compose logs -ft procrastinate
$ docker compose logs -ft procrastinate
```

Use the `procrastinate defer` command to create a job:

```console
$ docker-compose run --rm procrastinate procrastinate defer procrastinate_demo.tasks.sum '{"a":3, "b": 5}'
$ docker compose run --rm procrastinate procrastinate defer procrastinate_demo.tasks.sum '{"a":3, "b": 5}'
```

Or run the demo main file:

```console
$ docker-compose run --rm procrastinate python -m procrastinate_demo
$ docker compose run --rm procrastinate python -m procrastinate_demo
```

Stop and remove all the containers (including the `postgres` container):

```console
$ docker-compose down
$ docker compose down
```

## Wait, there are `async` and `await` keywords everywhere!?
Expand Down
2 changes: 1 addition & 1 deletion dev-env
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export GID=$(id -g)
if ! pg_isready ; then
echo "Starting database"
export PGDATABASE=procrastinate PGHOST=127.0.0.1 PGUSER=postgres PGPASSWORD=password
docker-compose up -d postgres || return
docker compose up -d postgres || return
sleep 3
fi

Expand Down
18 changes: 0 additions & 18 deletions docs/howto/advanced/sync_defer.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ app = App(connector=SQLAlchemyPsycopg2Connector())
app.open(engine)
```

## Having multiple apps

If you need to have multiple connectors interact with the tasks, you can
create multiple synchronized apps with {py:meth}`App.with_connector`:

```
import procrastinate


app = procrastinate.App(
connector=procrastinate.PsycopgConnector(...),
)

sync_app = app.with_connector(
connector=procrastinate.SyncPsycopgConnector(...),
)
```

## Procrastinate's automatic connector selection

Async connectors are able to summon their synchronous counterpart when needed
Expand Down
33 changes: 28 additions & 5 deletions docs/howto/basics/defer.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ There are several ways to do this.

In the following examples, the task will be:

```
```python
@app.task(queue="some_queue")
def my_task(a: int, b:int):
pass
Expand All @@ -14,39 +14,62 @@ Task name is `my_module.my_task`.

## The direct way

```
By using the sync method:

```python
my_task.defer(a=1, b=2)
```

## With parameters
Or the async method:

```python
await my_task.defer_async(a=1, b=2)
```

## With parameters

Using the sync defer method:

```python
my_task.configure(
lock="the name of my lock",
schedule_in={"hours": 1},
queue="not_the_default_queue"
).defer(a=1, b=2)

# or
await my_task.configure(
lock="the name of my lock",
schedule_in={"hours": 1},
queue="not_the_default_queue"
).defer_async(a=1, b=2)
```

See details in {py:meth}`Task.configure`

## Create a job pattern, launch multiple jobs

```
```python
pattern = my_task.configure(task_kwargs={"a": 1})

pattern.defer(b=2)
pattern.defer(b=3)
pattern.defer(b=4)
# or
await pattern.defer_async(b=2)
await pattern.defer_async(b=3)
await pattern.defer_async(b=4)
```

## Defer a job if you can't access the task

This is useful if the code that defers jobs is not in the same code base as the code
that runs the jobs. You can defer a job with just the name of its task.

```
```python
app.configure_task(name="my_module.my_task", queue="some_queue").defer(a=1, b=2)
# or
await app.configure_task(name="my_module.my_task", queue="some_queue").defer_async(a=1, b=2)
```

Any parameter you would use for {py:meth}`Task.configure` can be used in
Expand Down
27 changes: 24 additions & 3 deletions docs/howto/basics/tasks.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
# Define a task

You can specify a task with:
Specify a sync task with:

```
```python
@app.task(...)
def mytask(argument, other_argument):
...
```

:::{note}
Each sync task runs in its own thread (independently of the worker thread).
:::

Or an async task with:

```python
@app.task(...)
async def mytask(argument, other_argument):
...
```

:::{note}
All async tasks run in the same event loop.
:::

See {py:meth}`App.task` for the exact parameters. In particular, you can define values for
`queue`, `lock` and `queueing_lock` that will be used as default values when
calling {py:meth}`Task.configure` or {py:meth}`Task.defer` on this task.

If you're OK with all the default parameters, you can omit parentheses after
`task`:

```
```python
@app.task
def mytask(argument, other_argument):
...

# or
@app.task
async def mytask(argument, other_argument):
...
```
4 changes: 2 additions & 2 deletions docs/howto/django/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def main():
django.setup()
# By default, the app uses the Django database connection, which is unsuitable
# for the worker.
app = app.with_connector(app.connector.get_worker_connector())
app.run_worker()
with app.replace_connector(app.connector.get_worker_connector()):
app.run_worker()

if __name__ == "__main__":
main()
Expand Down
22 changes: 11 additions & 11 deletions docs/howto/django/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def app():
# Replace the connector in the current app
# Note that this fixture gives you the app back for convenience, but it's
# the same instance as you'd get with `procrastinate.contrib.django.app`.
with procrastinate_app.current_app.replace_connector(in_memory) as app_with_connector:
yield app_with_connector
with procrastinate_app.current_app.replace_connector(in_memory) as app:
yield app

def test_my_task(app):
# Run the task
Expand Down Expand Up @@ -126,8 +126,8 @@ class TestingTaskClass(TransactionTestCase):
my_task.defer(a=1, b=2)

# Start worker
app = app.with_connector(app.connector.get_worker_connector())
app.run_worker(wait=False, install_signal_handlers=False, listen_notify=False)
with app.replace_connector(app.connector.get_worker_connector())
app.run_worker(wait=False, install_signal_handlers=False, listen_notify=False)

# Check task has been executed
assert ProcrastinateJob.objects.filter(task_name="my_task").status == "succeeded"
Expand All @@ -144,20 +144,20 @@ def test_task():
my_task.defer(a=1, b=2)

# Start worker
app = app.with_connector(app.connector.get_worker_connector())
app.run_worker(wait=False, install_signal_handlers=False, listen_notify=False)
with app.replace_connector(app.connector.get_worker_connector())
app.run_worker(wait=False, install_signal_handlers=False, listen_notify=False)

# Check task has been executed
assert ProcrastinateJob.objects.filter(task_name="my_task").status == "succeeded"

# Or with a fixture
@pytest.fixture
def worker(transactional_db):
def _():
app = app.with_connector(app.connector.get_worker_connector())
app.run_worker(wait=False, install_signal_handlers=False, listen_notify=False)
return app
return _
with app.replace_connector(app.connector.get_worker_connector())
def f():
app.run_worker(wait=False, install_signal_handlers=False, listen_notify=False)
return app
yield f

def test_task(worker):
# Run tasks
Expand Down
Loading
Loading