Changeset e424270 in trunk
- Timestamp:
- 2019-03-08T12:46:36Z (6 years ago)
- Branches:
- master
- Children:
- c45b91e
- Parents:
- c8a3dbf (diff), 39694fc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Jean-Paul Calderone <exarkun@…> (2019-03-08 12:46:36)
- git-committer:
- GitHub <noreply@…> (2019-03-08 12:46:36)
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/frontends/magic_folder.py ¶
rc8a3dbf re424270 1765 1765 return d.addActionFinish() 1766 1766 1767 @eliotutil.log_call_deferred(SCAN_REMOTE_COLLECTIVE.action_type) 1767 1768 def _scan_remote_collective(self, scan_self=False): 1768 1769 scan_batch = {} # path -> [(filenode, metadata)] 1769 with SCAN_REMOTE_COLLECTIVE().context(): 1770 d = DeferredContext(self._collective_dirnode.list()) 1770 d = DeferredContext(self._collective_dirnode.list()) 1771 1771 def scan_collective(dirmap): 1772 1772 d2 = DeferredContext(defer.succeed(None)) … … 1807 1807 1808 1808 d.addCallback(_filter_batch_to_deque) 1809 return d. addActionFinish()1809 return d.result 1810 1810 1811 1811 def _scan_delay(self): 1812 1812 return self._poll_interval 1813 1813 1814 @eliotutil.log_call_deferred(PERFORM_SCAN.action_type) 1814 1815 @eliotutil.inline_callbacks 1815 1816 def _perform_scan(self): 1816 with PERFORM_SCAN(): 1817 try: 1818 yield self._scan_remote_collective() 1819 self._status_reporter( 1820 True, 'Magic folder is working', 1821 'Last scan: %s' % self.nice_current_time(), 1822 ) 1823 except Exception as e: 1824 write_traceback() 1825 self._status_reporter( 1826 False, 'Remote scan has failed: %s' % str(e), 1827 'Last attempted at %s' % self.nice_current_time(), 1828 ) 1817 try: 1818 yield self._scan_remote_collective() 1819 self._status_reporter( 1820 True, 'Magic folder is working', 1821 'Last scan: %s' % self.nice_current_time(), 1822 ) 1823 except Exception as e: 1824 write_traceback() 1825 self._status_reporter( 1826 False, 'Remote scan has failed: %s' % str(e), 1827 'Last attempted at %s' % self.nice_current_time(), 1828 ) 1829 1829 1830 1830 def _process(self, item): -
TabularUnified src/allmydata/test/test_eliotutil.py ¶
rc8a3dbf re424270 22 22 from testtools.matchers import ( 23 23 Is, 24 IsInstance, 24 25 MatchesStructure, 25 26 Equals, … … 29 30 has_no_result, 30 31 succeeded, 32 failed, 31 33 ) 32 34 … … 56 58 eliot_friendly_generator_function, 57 59 inline_callbacks, 60 log_call_deferred, 58 61 _parse_destination_description, 59 62 _EliotLogging, … … 528 531 ), 529 532 ) 533 534 class LogCallDeferredTests(TestCase): 535 """ 536 Tests for ``log_call_deferred``. 537 """ 538 @capture_logging( 539 lambda self, logger: 540 assertHasAction(self, logger, u"the-action", succeeded=True), 541 ) 542 def test_return_value(self, logger): 543 """ 544 The decorated function's return value is passed through. 545 """ 546 result = object() 547 @log_call_deferred(action_type=u"the-action") 548 def f(): 549 return result 550 self.assertThat(f(), succeeded(Is(result))) 551 552 @capture_logging( 553 lambda self, logger: 554 assertHasAction(self, logger, u"the-action", succeeded=False), 555 ) 556 def test_raise_exception(self, logger): 557 """ 558 An exception raised by the decorated function is passed through. 559 """ 560 class Result(Exception): 561 pass 562 @log_call_deferred(action_type=u"the-action") 563 def f(): 564 raise Result() 565 self.assertThat( 566 f(), 567 failed( 568 AfterPreprocessing( 569 lambda f: f.value, 570 IsInstance(Result), 571 ), 572 ), 573 ) -
TabularUnified src/allmydata/test/test_magic_folder.py ¶
rc8a3dbf re424270 42 42 from ..util.eliotutil import ( 43 43 inline_callbacks, 44 log_call_deferred, 44 45 ) 45 46 … … 524 525 self._fake_inotify = inject_events 525 526 527 @log_call_deferred(action_type=u"fileops:move") 526 528 def move(self, from_path_u, to_path_u): 527 529 from_fname = from_path_u … … 535 537 return d 536 538 539 @log_call_deferred(action_type=u"fileops:write") 537 540 def write(self, path_u, contents): 538 541 fname = path_u … … 547 550 return d 548 551 552 @log_call_deferred(action_type=u"fileops:mkdir") 549 553 def mkdir(self, path_u): 550 554 fname = path_u … … 554 558 return d 555 559 560 @log_call_deferred(action_type=u"fileops:delete") 556 561 def delete(self, path_u): 557 562 fname = path_u -
TabularUnified src/allmydata/util/eliotutil.py ¶
rc8a3dbf re424270 54 54 ILogger, 55 55 Message, 56 Field, 56 57 FileDestination, 57 58 add_destinations, 58 59 remove_destination, 59 60 write_traceback, 60 ) 61 from eliot import ( 62 Field, 61 start_action, 63 62 ) 64 63 from eliot._validation import ( 65 64 ValidationError, 66 65 ) 66 from eliot.twisted import DeferredContext 67 67 68 68 from twisted.python.usage import ( … … 82 82 from twisted.internet.defer import ( 83 83 inlineCallbacks, 84 maybeDeferred, 84 85 ) 85 86 from twisted.application.service import Service … … 471 472 472 473 _parse_destination_description = _DestinationParser().parse 474 475 def log_call_deferred(action_type): 476 """ 477 Like ``eliot.log_call`` but for functions which return ``Deferred``. 478 """ 479 def decorate_log_call_deferred(f): 480 @wraps(f) 481 def logged_f(*a, **kw): 482 # Use the action's context method to avoid ending the action when 483 # the `with` block ends. 484 with start_action(action_type=action_type).context(): 485 # Use addActionFinish so that the action finishes when the 486 # Deferred fires. 487 d = maybeDeferred(f, *a, **kw) 488 return DeferredContext(d).addActionFinish() 489 return logged_f 490 return decorate_log_call_deferred
Note: See TracChangeset
for help on using the changeset viewer.