def init_first_report(): report = get_first_report() message = Message.create(MessageType.INFO, body=report) transfer = get_current_transfer() result = get_io_loop().run_sync(lambda: transfer.send(message)) if not result: logger.error('Upload report failed') sys.exit(-1)
def test_mock_transfer(): class MockedTransfer(object): pass mocked_transfer = MockedTransfer() with mock_transfer(mocked_transfer): transfer = get_current_transfer() assert transfer is mocked_transfer
def eventloop(self): while True: try: yield gen.sleep(config['message_resend_interval']) now = datetime.datetime.now() logger.info('Check message cache before %s', now) messages = yield cache.get_messages_before(now) if messages: logger.info('Found %d messages in cache', len(messages)) else: logger.info('No message in cache') continue transfer = get_current_transfer() logger.info('Start to resend messages') result = yield transfer.send(messages) if result: logger.info('Resend successfully') yield cache.delete_messages_before(now) logger.info('Cache cleared') except Exception as exc: logger.error('Error while resending messages: %s', exc)
def initialize(self, **kwargs): self._transfer = kwargs.get('transfer') or get_current_transfer()
import os
def __init__(self): self._transfer = get_current_transfer()