From 436b91b46389d22e45ed93e87cb06e6f17319cef Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 25 Feb 2019 21:25:27 -0500 Subject: [PATCH] oops @log_call is not Deferred friendly --- src/allmydata/frontends/magic_folder.py | 71 +++++++++++++++---------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index ba4abc65e..74b9d578b 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -771,6 +771,20 @@ ALL_FILES = MessageType( u"A record of the rough state of the local database at the time of downloader start up.", ) +START_DOWNLOADING = ActionType( + u"magic-folder:start-downloading", + [_NICKNAME, _DIRECTION], + [], + u"A Magic-Folder downloader is initializing and beginning to manage downloads.", +) + +PERFORM_SCAN = ActionType( + u"magic-folder:perform-scan", + [], + [], + u"Remote storage is being scanned for changes which need to be synchronized.", +) + class QueueMixin(HookMixin): """ A parent class for Uploader and Downloader that handles putting @@ -1551,24 +1565,25 @@ class Downloader(QueueMixin, WriteFileMixin): self._status_reporter = status_reporter self._poll_interval = poll_interval - @log_call @eliotutil.inline_callbacks def start_downloading(self): - ALL_FILES.log(files=self._db.get_all_relpaths()) + action = START_DOWNLOADING(**self._log_fields) + with action: + ALL_FILES.log(files=self._db.get_all_relpaths()) - while True: - try: - data = yield self._scan_remote_collective(scan_self=True) - self._begin_processing() - defer.returnValue(data) - break - except Exception: - self._status_reporter( - False, "Initial scan has failed", - "Last tried at %s" % self.nice_current_time(), - ) - write_traceback() - yield task.deferLater(self._clock, self._poll_interval, lambda: None) + while True: + try: + data = yield self._scan_remote_collective(scan_self=True) + self._begin_processing() + defer.returnValue(data) + break + except Exception: + self._status_reporter( + False, "Initial scan has failed", + "Last tried at %s" % self.nice_current_time(), + ) + write_traceback() + yield task.deferLater(self._clock, self._poll_interval, lambda: None) def nice_current_time(self): return format_time(datetime.fromtimestamp(self._clock.seconds()).timetuple()) @@ -1714,21 +1729,21 @@ class Downloader(QueueMixin, WriteFileMixin): def _scan_delay(self): return self._poll_interval - @log_call @eliotutil.inline_callbacks def _perform_scan(self): - try: - yield self._scan_remote_collective() - self._status_reporter( - True, 'Magic folder is working', - 'Last scan: %s' % self.nice_current_time(), - ) - except Exception as e: - write_traceback() - self._status_reporter( - False, 'Remote scan has failed: %s' % str(e), - 'Last attempted at %s' % self.nice_current_time(), - ) + with PERFORM_SCAN(): + try: + yield self._scan_remote_collective() + self._status_reporter( + True, 'Magic folder is working', + 'Last scan: %s' % self.nice_current_time(), + ) + except Exception as e: + write_traceback() + self._status_reporter( + False, 'Remote scan has failed: %s' % str(e), + 'Last attempted at %s' % self.nice_current_time(), + ) def _process(self, item): """