Enable transactional job scheduling via externally managed DB connections
Hey folks, I’ve been experimenting with the library for a few days, and I think we’re missing out on transactional control of jobs.
The transactional outbox pattern ([related issue](https://github.com/procrastinate-org/procrastinate/issues/1318)) is valuable here, but it doesn’t require coupling to message brokers. Since Postgres is already in use, this could be achieved by allowing the caller to pass an externally managed database connection and deferring commits to the caller.
This would enable stronger consistency guarantees between business data and scheduled jobs/events.
Conceptually, it could look like this:
```python
async with managed_connection:
await task.configure(connection=managed_connection).defer_async(...)
# business DB operations
await managed_connection.commit()
```
This way, job scheduling participates in the same transaction as domain changes, ensuring atomicity without introducing additional infrastructure or coupling.
1 条评论