Exemple #1
0
    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_exit('stopped',
                                              account_id=self.account_id,
                                              folder_name=self.folder_name))
Exemple #2
0
    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_exit('stopped',
                                              account_id=self.account_id))
Exemple #3
0
 def _run_impl(self):
     sync = Greenlet(retry_and_report_killed, self.sync, self.log,
                     account_id=self.account_id)
     sync.link_value(lambda _: report_exit('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 for {0}".format(
                     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)
     assert not sync.successful(), \
         "mail sync for {} account {} should run forever!"\
         .format(self.provider, self.account_id)
     raise sync.exception
Exemple #4
0
def retry_and_report_killed(func, logger, account_id, folder_name=None):
    exc_callback = lambda: log_uncaught_errors(logger)
    fail_callback = lambda: report_exit('killed', account_id, folder_name)
    return retry(func, exc_callback=exc_callback,
                 fail_callback=fail_callback)()