~djfroofy/storm/twisted-oracle

« back to all changes in this revision

Viewing changes to storm/twisted/store.py

  • Committer: Drew Smathers
  • Date: 2009-06-10 21:32:22 UTC
  • Revision ID: drew@kieru-20090610213222-2e6816kpdu70e05q
don't return Store to StorePool if it can't be rolled back

Show diffs side-by-side

added added

removed removed

Lines of Context:
319
319
        """
320
320
        Add the created store to the list of available stores.
321
321
        """
322
 
        self._stores.append(store)
 
322
        if self._pending_get:
 
323
            # People are waiting, fire with the store
 
324
            d = self._pending_get.pop(0)
 
325
            d.callback(store)
 
326
        else:
 
327
            self._stores.append(store)
323
328
        self._store_refs.append(store)
324
329
 
325
330
 
425
430
        >>> d2.addCallback(doSomething).addErrback(manageErrors)
426
431
        >>> d2.addBoth(lambda x: pool.put(store))
427
432
        """
428
 
        return store.rollback().addCallback(self._cb_put, store)
 
433
        return store.rollback().addCallback(self._cb_put, store
 
434
                ).addErrback(self._eb_put, store)
429
435
 
430
436
 
431
437
    def _cb_put(self, ign, store):
440
446
            self._stores.append(store)
441
447
 
442
448
 
 
449
    def _eb_put(self, ign, store):
 
450
        """
 
451
        The store failed rolling back. Since the connection is likely
 
452
        in a bad state - don't return to pool.
 
453
        """
 
454
        d = self.stop_store([store])
 
455
        wfd = waitForDeferred(d)
 
456
        yield wfd
 
457
        wfd.getResult()
 
458
        
 
459
        del store
 
460
 
 
461
        def start_store(ign=None):
 
462
            from twisted.internet import reactor
 
463
            reactor.callLater(0, lambda :
 
464
                self.start_store().addErrback(start_store))
 
465
 
 
466
        start_store()
 
467
        
 
468
 
 
469
    _eb_put = deferredGenerator(_eb_put)
 
470
 
443
471
    def transact(self, f, *args, **kwargs):
444
472
        """
445
473
        Call function C{f} with a L{Store} instance and arguments C{args} and