Hello guys,
a
In my Rails 4 with Ruby 2 app I've the following model:

A Playlist can have many Tracks and each Track has its position in its Playlist. For each new Track I want to set its position to be the last, in thread-safe and/or multi-process-safe way.
In my research I found a bunch of projects that handle background jobs but I don't want this to be background, I want it to be synchronous. So the caller of my API will get the response with the correct position.
The question is: what's the best way to make a synchronous serial queue that will be used to set the position of a Track in its Playlist?
From what I've seen in QC docs the perfect solution for me would be to have dynamic queues (possible?) and one for each Playlist. But it might be too much for such a simple operation like that.
This is what the worker would execute for each Track that gets added:
def set_next_position
unless self.playlist_id.nil?
max = Track.where(playlist_id: self.playlist_id).maximum(:position) || 0
self.position = max + 1
end
end
I want to avoid problems where another Track could be added in between the `select max` and `max + 1` so I don't end up with duplicate positions.
Thanks,
P.S.: Sorry Ryan that I sent you a direct email I missed the link to this group the first time I read the README.