Move uploader's _append_to_deque and _turn_deque to QueueMixin.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2015-07-30 18:04:44 +01:00
parent b51563fe1e
commit 50c2cc575f

View File

@ -113,6 +113,25 @@ class QueueMixin(object):
#print "_log %s" % (msg,)
#open("events", "ab+").write(msg)
def _append_to_deque(self, path):
if path in self._pending:
return
self._deque.append(path)
self._pending.add(path)
self._count('objects_queued')
if self.is_ready:
reactor.callLater(0, self._turn_deque)
def _turn_deque(self):
try:
path = self._deque.pop()
except IndexError:
self._log("magic folder upload deque is now empty")
self._lazy_tail = defer.succeed(None)
return
self._lazy_tail.addCallback(lambda ign: task.deferLater(reactor, 0, self._process, path))
self._lazy_tail.addCallback(lambda ign: self._turn_deque())
def _do_callback(self, res):
if self._ignore_count == 0:
self._callback(res)
@ -246,27 +265,6 @@ class Uploader(QueueMixin):
return d
# FIXME move to QueueMixin
def _append_to_deque(self, path):
if path in self._pending:
return
self._deque.append(path)
self._pending.add(path)
self._counter('magic_folder.objects_queued', 1)
if self.is_ready:
reactor.callLater(0, self._turn_deque)
# FIXME move to QueueMixin
def _turn_deque(self):
try:
path = self._deque.pop()
except IndexError:
self._log("magic folder upload deque is now empty")
self._lazy_tail = defer.succeed(None)
return
self._lazy_tail.addCallback(lambda ign: task.deferLater(reactor, 0, self._process, path))
self._lazy_tail.addCallback(lambda ign: self._turn_deque())
def _notify(self, opaque, path, events_mask):
self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask))))
path_u = unicode_from_filepath(path)