Beispiel #1
0
 def __init__(self, notify_async: bool = None, *args, **kwargs) -> None:
     """
     :param notify_async: If True, enable ansynchronous (and reliable) notifications. If False, disable them.
                          If None, use external configuration to determine whether to enable them.
     """
     super().__init__(*args, **kwargs)
     if notify_async is None:
         notify_async = Config.notification_is_async()
     self.notifier = Notifier.from_config() if notify_async else None
Beispiel #2
0
    def test_notifier_from_config(self):
        with mock.patch.dict(os.environ,
                             DSS_NOTIFY_DELAYS="",
                             DSS_NOTIFY_WORKERS="",
                             DSS_NOTIFY_ATTEMPTS=""):
            self.assertFalse(Config.notification_is_async())
            self.assertEqual(Config.notification_attempts(), 0)
            self.assertEqual(Config.notification_delays(), [])
            with mock.patch.dict(os.environ, DSS_NOTIFY_DELAYS="0"):
                self.assertTrue(Config.notification_is_async())
                self.assertEqual(Config.notification_attempts(), 1)
                self.assertEqual(Config.notification_delays(), [0])
                with mock.patch.dict(os.environ, DSS_NOTIFY_ATTEMPTS="0"):
                    self.assertEqual(Config.notification_attempts(), 0)
                    self.assertFalse(Config.notification_is_async())

        with mock.patch.dict(os.environ,
                             DSS_NOTIFY_DELAYS="3 2 1 .5",
                             DSS_NOTIFY_WORKERS="7"):
            notifier = Notifier.from_config()
            self.assertEqual([3.0, 2.0, 1.0, .5], notifier._delays)
            self.assertEqual(7, notifier._num_workers)
            self.assertTrue(Config.notification_is_async())
            self.assertEqual(Config.notification_attempts(), 4)