Reputation: 13407
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:
SendEmailJob
processes email at one time.SendEmailJob
isn't running. If it is running, then there's no issue as that job will get to it in ~3 seconds.What I'm thinking...
SendEmailJob
could be running at once, as long as they abort early if there is a lock in place.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