Commit 82a27a73 authored by Ignacio Corderi's avatar Ignacio Corderi
Browse files

Reduced the client surface for batch operations

parent 0db5aea9
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -18,10 +18,10 @@

import common
import logging
import operations

LOG = logging.getLogger(__name__)


class Batch(object):
    """
    The Batch class is used for grouping a set of put and/or delete operations
@@ -71,9 +71,10 @@ class Batch(object):
            raise common.BatchCompletedException()

        self._op_count += 1        
        #TODO: add batch put logging
        kwargs['batch_id'] = self._batch_id
        self._client.batch_put(*args, **kwargs)
        kwargs['no_ack'] = True
        
        self._client.put(*args, **kwargs)

    def delete(self, *args, **kwargs):
        """
@@ -95,9 +96,10 @@ class Batch(object):
            raise common.BatchCompletedException()

        self._op_count += 1
        #TODO: add batch delete logging
        kwargs['batch_id'] = self._batch_id
        self._client.batch_delete(*args, **kwargs)
        kwargs['no_ack'] = True
        
        self._client.delete(*args, **kwargs)

    def commit(self, *args, **kwargs):
        """
@@ -116,11 +118,10 @@ class Batch(object):
        if self._batch_completed:
            raise common.BatchCompletedException()

        #TODO: add batch commit logging
        kwargs['batch_id'] = self._batch_id
        kwargs['batch_op_count'] = self._op_count
        try:
            self._client.batch_commit(*args, **kwargs)
            self._client._process(operations.EndBatch(), *args, **kwargs)
            self._batch_completed = True
        except BatchAbortedException:
            self._batch_completed = True
@@ -140,9 +141,8 @@ class Batch(object):
        if self._batch_completed:
            raise common.BatchCompletedException()

        #TODO: add batch abort logging
        kwargs['batch_id'] = self._batch_id
        self._client.batch_abort(*args, **kwargs)
        self._client._process(operations.AbortBatch(), *args, **kwargs)
        self._batch_completed = True

    def is_completed(self):
@@ -152,7 +152,7 @@ class Batch(object):
        """
        return self._batch_completed

    def operation_count(self):
    def __len__(self):
        """
        Return the number of operations that have been included in the batch.
        """
+1 −23
Original line number Diff line number Diff line
@@ -101,31 +101,9 @@ class BlockingClient(BaseClient):
    def begin_batch(self, *args, **kwargs):
        next_batch_id = self.next_batch_id()
        kwargs['batch_id'] = next_batch_id
        self.batch_begin(*args, **kwargs)
        self._process(operations.StartBatch(), *args, **kwargs)
        return batch.Batch(self, next_batch_id)

    # @RequiresProtocol('3.0.6')
    def batch_begin(self, *args, **kwargs):
        return self._process(operations.StartBatch(), *args, **kwargs)

    # @RequiresProtocol('3.0.6')
    def batch_put(self, *args, **kwargs):
        kwargs['no_ack'] = True
        return self.put(*args, **kwargs)

    # @RequiresProtocol('3.0.6')
    def batch_delete(self, *args, **kwargs):
        kwargs['no_ack'] = True
        return self.delete(*args, **kwargs)

    # @RequiresProtocol('3.0.6')
    def batch_commit(self, *args, **kwargs):
        return self._process(operations.EndBatch(), *args, **kwargs)

    # @RequiresProtocol('3.0.6')
    def batch_abort(self, *args, **kwargs):
        return self._process(operations.AbortBatch(), *args, **kwargs)

    # @RequiresProtocol('3.0.0')
    def mediaScan(self, *args, **kwargs):
        return self._process(operations.MediaScan(), *args, **kwargs)