Skip to content

Commit f8b3e6a

Browse files
committed
Add section on custom advisory lock prefixes
Add a section in the README on using custom advisory lock prefixes to guarantee that River's advisory locks can never conflict with an application's that using it.
1 parent 3ab20e9 commit f8b3e6a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ insert_res.job
8181
insert_res.unique_skipped_as_duplicated
8282
```
8383

84+
### Custom advisory lock prefix
85+
86+
Unique job insertion takes a Postgres advisory lock to make sure that it's uniqueness check still works even if two conflicting insert operations are occurring in parallel. Postgres advisory locks share a global 64-bit namespace, which is a large enough space that it's unlikely for two advisory locks to ever conflict, but to _guarantee_ that River's advisory locks never interfere with an application's, River can be configured with a 32-bit advisory lock prefix which it will use for all its locks:
87+
88+
```ruby
89+
client = River::Client.new(mock_driver, advisory_lock_prefix: 123456)
90+
```
91+
92+
Doing so has the downside of leaving only 32 bits for River's locks (64 bits total - 32-bit prefix), making them somewhat more likely to conflict with each other.
93+
8494
## Inserting jobs in bulk
8595

8696
Use `#insert_many` to bulk insert jobs as a single operation for improved efficiency:

0 commit comments

Comments
 (0)