Skip to content

Commit

Permalink
fixing possible race condition on asset delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Simon committed Jul 25, 2012
1 parent f494cd5 commit f2d1805
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion collins/app/util/Solr.scala
Expand Up @@ -178,9 +178,12 @@ class SolrUpdater extends Actor {
/**
* Note, even though the callback checks if the asset is deleted, we're still
* gonna get index requests from the delete asset's meta value deletions
*
* Note - also we re-fetch the asset from MySQL to avoid a possible race
* condition where an asset is deleted immediately after it is updated
*/
def receive = {
case asset: Asset => if (!queue.contains(asset) && !asset.deleted.isDefined) {
case asset: Asset => if ((!queue.contains(asset)) && Asset.findByTag(asset.tag).map{_.deleted.isDefined == false}.getOrElse(false)) {
queue += asset
if (!scheduled) {
context.system.scheduler.scheduleOnce(10 milliseconds, self, Reindex)
Expand Down
5 changes: 3 additions & 2 deletions collins/test/spec/update.rb
Expand Up @@ -12,10 +12,11 @@ def foo
end

it "put asset in maintenance mode" do
#the asset should be in allocated mode, but might not if a previous test failed
assets = @client.search 'tag = "001016"'
assets.size.should eql 1
@client.set_status!(assets[0], "Maintenance")
#the asset should be in allocated mode, but might not if a previous test failed
@client.set_status!(assets[0], "Allocated").should eql true
@client.set_status!(assets[0], "Maintenance").should eql true
sleep(0.2)
assets = @client.search 'tag = "001016" AND status = maintenance'
assets.size.should eql 1
Expand Down

0 comments on commit f2d1805

Please sign in to comment.