def _run_impl(self): sync = Greenlet(retry_and_report_killed, self.sync, account_id=self.account_id, logger=self.log) sync.link_value(lambda _: report_stopped(account_id=self.account_id)) sync.start() while not sync.ready(): try: cmd = self.inbox.get_nowait() if not self.process_command(cmd): # ctrl-c, basically! self.log.info("Stopping sync", email=self.email_address) # make sure the parent can't start/stop any folder monitors # first sync.kill(block=True) self.folder_monitors.kill() return except Empty: sleep(self.heartbeat) if sync.successful(): self.folder_monitors.kill() return self.log.error("mail sync should run forever", provider=self.provider_name, account_id=self.account_id) raise sync.exception
def __init__(self, account_id, folder_name, folder_id, email_address, provider, shared_state, state_handlers): self.account_id = account_id self.folder_name = folder_name self.folder_id = folder_id self.shared_state = shared_state self.state_handlers = state_handlers self.state = None self.conn_pool = connection_pool(self.account_id) self.log = get_logger(account_id, 'mailsync') Greenlet.__init__(self) self.link_value(lambda _: report_stopped(account_id=self.account_id, folder_name=self.folder_name))
def __init__(self, account_id, email_address, provider, heartbeat=1): self.inbox = Queue() # how often to check inbox, in seconds self.heartbeat = heartbeat self.log = configure_mailsync_logging(account_id) self.account_id = account_id self.email_address = email_address self.provider = provider # Stuff that might be updated later and we want to keep a shared # reference on child greenlets. if not hasattr(self, 'shared_state'): self.shared_state = dict() Greenlet.__init__(self) self.link_value(lambda _: report_stopped(self.account_id))
def __init__(self, account_id, folder_name, folder_id, email_address, provider_name, shared_state, state_handlers, retry_fail_classes): self.account_id = account_id self.folder_name = folder_name self.folder_id = folder_id self.shared_state = shared_state self.state_handlers = state_handlers self.state = None self.conn_pool = _pool(self.account_id) self.retry_fail_classes = retry_fail_classes self.log = logger.new(account_id=account_id, folder=folder_name) Greenlet.__init__(self) self.link_value(lambda _: report_stopped(account_id=self.account_id, folder_name=self.folder_name))
def __init__(self, account, heartbeat=1, retry_fail_classes=[]): self.inbox = Queue() # how often to check inbox, in seconds self.heartbeat = heartbeat self.log = logger.new(component='mail sync', account_id=account.id) self.account_id = account.id self.email_address = account.email_address self.provider_name = account.provider self.retry_fail_classes = self.RETRY_FAIL_CLASSES self.retry_fail_classes.extend(retry_fail_classes) # Stuff that might be updated later and we want to keep a shared # reference on child greenlets. if not hasattr(self, 'shared_state'): self.shared_state = dict() Greenlet.__init__(self) self.link_value(lambda _: report_stopped(self.account_id))
def __init__(self, account_id, email_address, provider, heartbeat=1, retry_fail_classes=[MailsyncError, ValueError, AttributeError, DataError, IntegrityError]): self.inbox = Queue() # how often to check inbox, in seconds self.heartbeat = heartbeat self.log = logger.new(component='mail sync', account_id=account_id) self.account_id = account_id self.email_address = email_address self.provider = provider self.retry_fail_classes = retry_fail_classes # Stuff that might be updated later and we want to keep a shared # reference on child greenlets. if not hasattr(self, 'shared_state'): self.shared_state = dict() Greenlet.__init__(self) self.link_value(lambda _: report_stopped(self.account_id))
def __init__(self, account_id, folder_name, folder_id, email_address, provider_name, poll_frequency, syncmanager_lock, refresh_flags_max, retry_fail_classes): self.account_id = account_id self.folder_name = folder_name self.folder_id = folder_id self.poll_frequency = poll_frequency self.syncmanager_lock = syncmanager_lock self.refresh_flags_max = refresh_flags_max self.retry_fail_classes = retry_fail_classes self.state = None self.conn_pool = _pool(self.account_id) self.state_handlers = { 'initial': self.initial_sync, 'initial uidinvalid': self.resync_uids_from('initial'), 'poll': self.poll, 'poll uidinvalid': self.resync_uids_from('poll'), 'finish': lambda self: 'finish', } Greenlet.__init__(self) self.link_value(lambda _: report_stopped(account_id=self.account_id, folder_name=self.folder_name))