Concurrent moderating on a CMS
I'm building a custom CMS which allow user to post message to it. Messages are short and like tweets.
The problem is that these message are moderated by real moderators. And there are multiple moderators working on the messages stream at the same time. And my concern is that what if these moderator are processing a same message. This is both inefficient and inconsistent. Since one message can be rejected by one moderator and then passed by another.
Therefore I want to build some kind of mechanism so that the CMS can distribute these messages to different moder开发者_JAVA百科ator and avoiding duplication. The CMS is expecting to deal with large volume of message in a short time. Therefore this problem become more serious.
Any Idea is appreciated. Cheers.
I would do it like this:
- Each logged-in moderator gets his own queue of messages to moderate
- There is a central queue which will be used as a buffert
- Posted messages go into the central queue
- Each moderator queue fetches, say, 10 messages at a time.
- When there's only 5 left in a moderator queue that queue will automatically fetch 10 new messages.
The downside is that you will need a central queue with a locking mechanism. If you want to avoid even that locking I propose one of two solutions:
- Remove the central queue entirely and post messages on-the-fly into one of the moderator queues (maybe a randmoly chosen one), or,
- Have a central queue and let each moderator have a randmoly chosen message from the top part of the queue (e.g., let them have one from the top-20). If there is "double moderation" due to absense of locking, just ignore the second moderation and accept the time-waste.
You could have the moderators pull the message off a queue before moderating. Sort-of like a check-out? So the moderator clicks something that assigns them a number of messages to process. They deal with those, then grab another batch off the queue.
Have your update action for Messages do this
def update
# perform regular update stuff ;)
rescue ActiveRecord::StaleObjectError
flash[:message] = "Someone else has updated this message"
redirect_to message_path(@message)
end
Check out http://railscasts.com/episodes/59-optimistic-locking or other pages on 'locking' (optimistic or otherwise) in Rails.
精彩评论