Tallboy
Tallboy

Reputation: 13407

Rails/Postgres - What type of DB lock do I need?

I have a PendingEmail table which I push many records to for emails I want to send.

I then have multiple Que workers which process my app's jobs. One of said jobs is my SendEmailJob.

The purpose of this job is to check PendingEmail, pull the latest 500 ordered by priority, make a batch request to my 3rd party email provider, wait for array response of all 500 responses, then delete the successful items and mark the failed records' error column. The single job will continue in this fashion until the records returned from the DB are 0, and the job will exit/destroy.

The issues are:

What I'm thinking...

I just don't know which type of lock to choose, whether to do it in Rails or in the database directly. There are so many of them with such subtle differences (I'm using PG). Any insight would be greatly appreciated!

Upvotes: 2

Views: 844

Answers (1)

Tallboy
Tallboy

Reputation: 13407

Answer: I needed an advisory lock.

Upvotes: 1

Related Questions