~nataliabidart/ubuntuone-client/credentials-shutdown

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/action_queue.py

  • Committer: Tarmac
  • Author(s): facundo at com
  • Date: 2011-01-07 12:21:24 UTC
  • mfrom: (782.2.1 unleash-the-queues-1)
  • Revision ID: tarmac-20110107122124-p9k4s3pvjmqc3wz9
Unleash the queues: some AQ small changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# Author: John Lenton <john.lenton@canonical.com>
4
4
# Author: Natalia B. Bidart <natalia.bidart@canonical.com>
 
5
# Author: Facundo Batista <facundo@canonical.com>
5
6
#
6
 
# Copyright 2009 Canonical Ltd.
 
7
# Copyright 2009, 2010, 2011 Canonical Ltd.
7
8
#
8
9
# This program is free software: you can redistribute it and/or modify it
9
10
# under the terms of the GNU General Public License version 3, as published
80
81
    return wrapper
81
82
 
82
83
 
 
84
class ClientNoLongerThere(Exception):
 
85
    """AQ Client is no longer there.
 
86
 
 
87
    This is used for Commands that have work to do after starting and before
 
88
    actually using the client, and in this time frame the client can
 
89
    disappear (connection lost, etc.).
 
90
    """
 
91
 
 
92
 
83
93
class UploadCompressionCancelled(Exception):
84
94
    """Compression of a file for upload cancelled."""
85
95
 
246
256
            d = self.waiting.popleft()
247
257
            d.callback(self)
248
258
 
249
 
    def _compress(self, deferred, upload):
 
259
    def _compress(self, deferred, upload, fileobj):
250
260
        """Compression background task."""
251
 
        try:
252
 
            fileobj = upload.fileobj_factory()
253
 
        except StandardError:
254
 
            # presumably the user deleted the file before we got to
255
 
            # upload it. Logging a warning just in case.
256
 
            upload.log.warn('unable to build fileobj'
257
 
                            ' (user deleted the file, maybe?)'
258
 
                            ' so cancelling the upload.')
259
 
            upload.cancel()
260
 
            fileobj = None
261
 
 
262
261
        filename = getattr(fileobj, 'name', '<?>')
263
262
 
264
263
        try:
300
299
 
301
300
        yield self.acquire()
302
301
        try:
303
 
            reactor.callInThread(self._compress, deferred, upload)
 
302
            fileobj = upload.fileobj_factory()
 
303
        except StandardError, e:
 
304
            # presumably the user deleted the file before we got to upload it
 
305
            upload.log.warn("Unable to build fileobj (%s: '%s') so cancelling "
 
306
                            "the upload.", type(e), e)
 
307
            upload.cancel()
 
308
            raise UploadCompressionCancelled("Cancelled because of "
 
309
                                             "fileobj_factory failure.")
 
310
 
 
311
        try:
 
312
            reactor.callInThread(self._compress, deferred, upload, fileobj)
304
313
        finally:
305
314
            self.release()
306
315
 
1186
1195
        protocol_errors.TryAgainError,
1187
1196
        twisted_errors.ConnectionDone,
1188
1197
        twisted_errors.ConnectionLost,
 
1198
        ClientNoLongerThere,
1189
1199
    )
1190
1200
 
1191
1201
    logged_attrs = ()
2365
2375
        """Do the actual running."""
2366
2376
        if self.cancelled:
2367
2377
            return defer.fail(RequestCleanedUp('CANCELLED'))
 
2378
 
 
2379
        # need to check if client is still there, as _start() may delay a lot
 
2380
        # the execution of this
 
2381
        if self.action_queue.client is None:
 
2382
            return defer.fail(ClientNoLongerThere('Detected in _run'))
 
2383
 
2368
2384
        uploading = {"hash": self.hash, "deflated_size": self.deflated_size,
2369
2385
                     "req": self}
2370
2386
        self.action_queue.uploading[self.share_id, self.node_id] = uploading