def start_sync(self, account_id): """ Starts a sync for the account with the given account_id. If that account doesn't exist, does nothing. """ with session_scope() as db_session: acc = db_session.query(Account).get(account_id) if acc is None: self.log.error('no such account', account_id=account_id) return fqdn = platform.node() self.log.info('starting sync', account_id=acc.id, email_address=acc.email_address) if acc.sync_host is not None and acc.sync_host != fqdn: self.log.error( 'Sync Host Mismatch', message='account is syncing on another host {}'.format( acc.sync_host), account_id=account_id) elif acc.id not in self.monitors: try: if acc.is_sync_locked and acc.is_killed: acc.sync_unlock() acc.sync_lock() monitor = self.monitor_cls_for[acc.provider](acc) self.monitors[acc.id] = monitor monitor.start() info = acc.provider_info if info.get('contacts', None) and acc.sync_contacts: contact_sync = ContactSync(acc.email_address, acc.provider, acc.id, acc.namespace.id) self.contact_sync_monitors[acc.id] = contact_sync contact_sync.start() if info.get('events', None) and acc.sync_events: event_sync = EventSync(acc.email_address, acc.provider, acc.id, acc.namespace.id) self.event_sync_monitors[acc.id] = event_sync event_sync.start() acc.sync_started() db_session.add(acc) db_session.commit() self.log.info('Sync started', account_id=account_id, sync_host=fqdn) except Exception as e: self.log.error('sync_error', message=str(e.message), account_id=account_id) else: self.log.info('sync already started', account_id=account_id)
def start_sync(self, account_id): """ Starts a sync for the account with the given account_id. If that account doesn't exist, does nothing. """ with session_scope() as db_session: acc = db_session.query(Account).get(account_id) if acc is None: self.log.error('no such account', account_id=account_id) return fqdn = platform.node() self.log.info('starting sync', account_id=acc.id, email_address=acc.email_address) if acc.sync_host is not None and acc.sync_host != fqdn: self.log.error('Sync Host Mismatch', message='account is syncing on another host {}' .format(acc.sync_host), account_id=account_id) elif acc.id not in self.monitors: try: if acc.is_sync_locked and acc.is_killed: acc.sync_unlock() acc.sync_lock() monitor = self.monitor_cls_for[acc.provider](acc) self.monitors[acc.id] = monitor monitor.start() info = acc.provider_info if info.get('contacts', None) and acc.sync_contacts: contact_sync = ContactSync(acc.email_address, acc.provider, acc.id, acc.namespace.id) self.contact_sync_monitors[acc.id] = contact_sync contact_sync.start() if info.get('events', None) and acc.sync_events: event_sync = EventSync(acc.email_address, acc.provider, acc.id, acc.namespace.id) self.event_sync_monitors[acc.id] = event_sync event_sync.start() acc.sync_started() db_session.add(acc) db_session.commit() self.log.info('Sync started', account_id=account_id, sync_host=fqdn) except Exception as e: self.log.error('sync_error', message=str(e.message), account_id=account_id) else: self.log.info('sync already started', account_id=account_id)
def start_sync(self, account_id): """ Starts a sync for the account with the given account_id. If that account doesn't exist, does nothing. """ with session_scope() as db_session: acc = db_session.query(Account).get(account_id) if acc is None: self.log.error('no such account', account_id=account_id) return fqdn = platform.node() self.log.info('starting sync', account_id=acc.id, email_address=acc.email_address) if acc.sync_host is not None and acc.sync_host != fqdn: self.log.warning('account is syncing on another host', account_id=account_id, email_address=acc.email_address, sync_host=acc.sync_host) elif acc.id not in self.monitors: try: if acc.is_sync_locked and acc.is_killed: acc.sync_unlock() acc.sync_lock() info = provider_info(acc.provider) provider_supports_condstore = info.get("condstore", None) account_supports_condstore = getattr(acc, 'supports_condstore', None) if (provider_supports_condstore or account_supports_condstore): # upgrade generic providers if they support condstore monitor = self.monitor_cls_for['generic_condstore']( acc.id, acc.namespace.id, acc.email_address, acc.provider) else: monitor = self.monitor_cls_for[acc.provider]( acc.id, acc.namespace.id, acc.email_address, acc.provider) self.monitors[acc.id] = monitor monitor.start() # For Gmail accounts, also start contacts and events sync if acc.provider == 'gmail': contact_sync = ContactSync(acc.id) self.contact_sync_monitors[acc.id] = contact_sync contact_sync.start() event_sync = EventSync(acc.id) self.event_sync_monitors[acc.id] = event_sync event_sync.start() acc.start_sync(fqdn) db_session.add(acc) db_session.commit() self.log.info('sync started', account_id=account_id) except Exception as e: self.log.error('error encountered', msg=e.message) else: self.log.info('sync already started', account_id=account_id)
def start_sync(self, account_id): """ Starts a sync for the account with the given account_id. If that account doesn't exist, does nothing. """ with session_scope() as db_session: acc = db_session.query(Account).get(account_id) if acc is None: self.log.error('no such account', account_id=account_id) return fqdn = platform.node() self.log.info('starting sync', account_id=acc.id, email_address=acc.email_address) if acc.sync_host is not None and acc.sync_host != fqdn: self.log.error( 'Sync Host Mismatch', message='account is syncing on another host {}'.format( acc.sync_host), account_id=account_id) elif acc.id not in self.monitors: # Before starting the sync, clear the heartbeat and individual # folder should_run bits. These bits will be flipped to the # correct state by the mailsync monitor. try: for status in acc.foldersyncstatuses: status.sync_should_run = False except Exception as e: self.log.error('Error resetting folder run status', message=str(e.message), account_id=acc.id) try: clear_heartbeat_status(acc.id) except Exception as e: self.log.error('Error clearing heartbeat on sync start', message=str(e.message), account_id=acc.id) try: if acc.is_sync_locked and acc.is_killed: acc.sync_unlock() acc.sync_lock() monitor = self.monitor_cls_for[acc.provider](acc) self.monitors[acc.id] = monitor monitor.start() info = acc.provider_info if info.get('contacts', None) and acc.sync_contacts: contact_sync = ContactSync(acc.email_address, acc.provider, acc.id, acc.namespace.id) self.contact_sync_monitors[acc.id] = contact_sync contact_sync.start() if info.get('events', None) and acc.sync_events: event_sync = EventSync(acc.email_address, acc.provider, acc.id, acc.namespace.id) self.event_sync_monitors[acc.id] = event_sync event_sync.start() acc.sync_started() db_session.add(acc) db_session.commit() self.log.info('Sync started', account_id=account_id, sync_host=fqdn) except Exception as e: self.log.error('sync_error', message=str(e.message), account_id=account_id) else: self.log.info('sync already started', account_id=account_id)
def start_sync(self, account_id): """ Starts a sync for the account with the given account_id. If that account doesn't exist, does nothing. """ with session_scope() as db_session: acc = db_session.query(Account).get(account_id) if acc is None: self.log.error('no such account', account_id=account_id) return fqdn = platform.node() self.log.info('starting sync', account_id=acc.id, email_address=acc.email_address) if acc.sync_host is not None and acc.sync_host != fqdn: self.log.warning('account is syncing on another host', account_id=account_id, email_address=acc.email_address, sync_host=acc.sync_host) elif acc.id not in self.monitors: try: if acc.is_sync_locked and acc.is_killed: acc.sync_unlock() acc.sync_lock() info = provider_info(acc.provider) provider_supports_condstore = info.get("condstore", None) account_supports_condstore = getattr( acc, 'supports_condstore', None) if (provider_supports_condstore or account_supports_condstore): # upgrade generic providers if they support condstore monitor = self.monitor_cls_for['generic_condstore']( acc.id, acc.namespace.id, acc.email_address, acc.provider) else: monitor = self.monitor_cls_for[acc.provider]( acc.id, acc.namespace.id, acc.email_address, acc.provider) self.monitors[acc.id] = monitor monitor.start() # For Gmail accounts, also start contacts and events sync if acc.provider == 'gmail': contact_sync = ContactSync(acc.id) self.contact_sync_monitors[acc.id] = contact_sync contact_sync.start() event_sync = EventSync(acc.id) self.event_sync_monitors[acc.id] = event_sync event_sync.start() acc.start_sync(fqdn) db_session.add(acc) db_session.commit() self.log.info('sync started', account_id=account_id) except Exception as e: self.log.error('error encountered', msg=e.message) else: self.log.info('sync already started', account_id=account_id)
def start_sync(self, account_id): """ Starts a sync for the account with the given account_id. If that account doesn't exist, does nothing. """ with session_scope() as db_session: acc = db_session.query(Account).get(account_id) if acc is None: self.log.error('no such account', account_id=account_id) return fqdn = platform.node() self.log.info('starting sync', account_id=acc.id, email_address=acc.email_address) if acc.sync_host is not None and acc.sync_host != fqdn: self.log.error('Sync Host Mismatch', message='account is syncing on another host {}' .format(acc.sync_host), account_id=account_id) elif acc.id not in self.monitors: # Before starting the sync, clear the heartbeat and individual # folder should_run bits. These bits will be flipped to the # correct state by the mailsync monitor. try: for status in acc.foldersyncstatuses: status.sync_should_run = False except Exception as e: self.log.error('Error resetting folder run status', message=str(e.message), account_id=acc.id) try: clear_heartbeat_status(acc.id) except Exception as e: self.log.error('Error clearing heartbeat on sync start', message=str(e.message), account_id=acc.id) try: if acc.is_sync_locked and acc.is_killed: acc.sync_unlock() acc.sync_lock() monitor = self.monitor_cls_for[acc.provider](acc) self.monitors[acc.id] = monitor monitor.start() info = acc.provider_info if info.get('contacts', None) and acc.sync_contacts: contact_sync = ContactSync(acc.email_address, acc.provider, acc.id, acc.namespace.id) self.contact_sync_monitors[acc.id] = contact_sync contact_sync.start() if info.get('events', None) and acc.sync_events: event_sync = EventSync(acc.email_address, acc.provider, acc.id, acc.namespace.id) self.event_sync_monitors[acc.id] = event_sync event_sync.start() acc.sync_started() db_session.add(acc) db_session.commit() self.log.info('Sync started', account_id=account_id, sync_host=fqdn) except Exception as e: self.log.error('sync_error', message=str(e.message), account_id=account_id) else: self.log.info('sync already started', account_id=account_id)