Revert _perform_scan to inlineCallbacks style

This commit is contained in:
Jean-Paul Calderone 2019-02-22 15:51:11 -05:00
parent 0a9a962614
commit 89e59dde05

View File

@ -24,7 +24,9 @@ from eliot import (
MessageType, MessageType,
write_failure, write_failure,
) )
from eliot.twisted import DeferredContext from eliot.twisted import (
DeferredContext,
)
from allmydata.util import ( from allmydata.util import (
fileutil, fileutil,
@ -1518,29 +1520,25 @@ class Downloader(QueueMixin, WriteFileMixin):
d.addCallback(_filter_batch_to_deque) d.addCallback(_filter_batch_to_deque)
return d.addActionFinish() return d.addActionFinish()
def _scan_delay(self): def _scan_delay(self):
return self._poll_interval return self._poll_interval
@eliotutil.inline_callbacks
def _perform_scan(self): def _perform_scan(self):
with PERFORM_SCAN().context(): with PERFORM_SCAN():
d = DeferredContext(defer.maybeDeferred(self._scan_remote_collective)) try:
def scanned(result): yield self._scan_remote_collective()
self._status_reporter( self._status_reporter(
True, 'Magic folder is working', True, 'Magic folder is working',
'Last scan: %s' % self.nice_current_time(), 'Last scan: %s' % self.nice_current_time(),
) )
return result except Exception as e:
def scan_failed(reason): twlog.msg("Remote scan failed: %s" % (e,))
twlog.msg("Remote scan failed: %s" % (reason.value,)) self._log("_scan failed: %s" % (repr(e),))
self._log("_scan failed: %s" % (repr(reason.value),)) self._status_reporter(
self._status_reporter( False, 'Remote scan has failed: %s' % str(e),
False, 'Remote scan has failed: %s' % str(reason.value), 'Last attempted at %s' % self.nice_current_time(),
'Last attempted at %s' % self.nice_current_time(), )
)
return None
d.addCallbacks(scanned, scan_failed)
return d.addActionFinish()
def _process(self, item): def _process(self, item):
# Downloader # Downloader