本文整理汇总了Python中inbox.heartbeat.store.HeartbeatStatusProxy类的典型用法代码示例。如果您正苦于以下问题:Python HeartbeatStatusProxy类的具体用法?Python HeartbeatStatusProxy怎么用?Python HeartbeatStatusProxy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HeartbeatStatusProxy类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, account_id, folder_name, folder_id, email_address,
provider_name, poll_frequency, syncmanager_lock,
refresh_flags_max, retry_fail_classes):
bind_context(self, 'foldersyncengine', account_id, folder_id)
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.provider_name = provider_name
with mailsync_session_scope() as db_session:
account = db_session.query(Account).get(self.account_id)
self.throttled = account.throttled
self.namespace_id = account.namespace.id
assert self.namespace_id is not None, "namespace_id is None"
self.state_handlers = {
'initial': self.initial_sync,
'initial uidinvalid': self.resync_uids,
'poll': self.poll,
'poll uidinvalid': self.resync_uids,
'finish': lambda self: 'finish',
}
Greenlet.__init__(self)
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
self.folder_id,
self.folder_name,
email_address,
self.provider_name)
示例2: __init__
def __init__(self, account_id, namespace_id, folder_name,
email_address, provider_name, syncmanager_lock):
with session_scope(namespace_id) as db_session:
try:
folder = db_session.query(Folder). \
filter(Folder.name == folder_name,
Folder.account_id == account_id).one()
except NoResultFound:
raise MailsyncError(u"Missing Folder '{}' on account {}"
.format(folder_name, account_id))
self.folder_id = folder.id
self.folder_role = folder.canonical_name
# Metric flags for sync performance
self.is_initial_sync = folder.initial_sync_end is None
self.is_first_sync = folder.initial_sync_start is None
self.is_first_message = self.is_first_sync
bind_context(self, 'foldersyncengine', account_id, self.folder_id)
self.account_id = account_id
self.namespace_id = namespace_id
self.folder_name = folder_name
if self.folder_name.lower() == 'inbox':
self.poll_frequency = INBOX_POLL_FREQUENCY
else:
self.poll_frequency = DEFAULT_POLL_FREQUENCY
self.syncmanager_lock = syncmanager_lock
self.state = None
self.provider_name = provider_name
self.last_fast_refresh = None
self.flags_fetch_results = {}
self.conn_pool = connection_pool(self.account_id)
self.state_handlers = {
'initial': self.initial_sync,
'initial uidinvalid': self.resync_uids,
'poll': self.poll,
'poll uidinvalid': self.resync_uids,
}
Greenlet.__init__(self)
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
self.folder_id,
self.folder_name,
email_address,
self.provider_name)
# Some generic IMAP servers are throwing UIDVALIDITY
# errors forever. Instead of resyncing those servers
# ad vitam, we keep track of the number of consecutive
# times we got such an error and bail out if it's higher than
# MAX_UIDINVALID_RESYNCS.
self.uidinvalid_count = 0
示例3: __init__
def __init__(self, account_id, namespace_id, folder_name,
email_address, provider_name, syncmanager_lock):
with session_scope(namespace_id) as db_session:
try:
folder = db_session.query(Folder). \
filter(Folder.name == folder_name,
Folder.account_id == account_id).one()
except NoResultFound:
raise MailsyncError(u"Missing Folder '{}' on account {}"
.format(folder_name, account_id))
self.folder_id = folder.id
self.folder_role = folder.canonical_name
# Metric flags for sync performance
self.is_initial_sync = folder.initial_sync_end is None
self.is_first_sync = folder.initial_sync_start is None
self.is_first_message = self.is_first_sync
bind_context(self, 'foldersyncengine', account_id, self.folder_id)
self.account_id = account_id
self.namespace_id = namespace_id
self.folder_name = folder_name
if self.folder_name.lower() == 'inbox':
self.poll_frequency = INBOX_POLL_FREQUENCY
else:
self.poll_frequency = DEFAULT_POLL_FREQUENCY
self.syncmanager_lock = syncmanager_lock
self.state = None
self.provider_name = provider_name
self.last_fast_refresh = None
self.conn_pool = connection_pool(self.account_id)
self.state_handlers = {
'initial': self.initial_sync,
'initial uidinvalid': self.resync_uids,
'poll': self.poll,
'poll uidinvalid': self.resync_uids,
}
Greenlet.__init__(self)
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
self.folder_id,
self.folder_name,
email_address,
self.provider_name)
示例4: __init__
def __init__(self, account_id, folder_name, folder_id, email_address,
provider_name, syncmanager_lock):
bind_context(self, 'foldersyncengine', account_id, folder_id)
self.account_id = account_id
self.folder_name = folder_name
self.folder_id = folder_id
if self.folder_name.lower() == 'inbox':
self.poll_frequency = INBOX_POLL_FREQUENCY
else:
self.poll_frequency = DEFAULT_POLL_FREQUENCY
self.syncmanager_lock = syncmanager_lock
self.state = None
self.provider_name = provider_name
self.last_fast_refresh = None
self.conn_pool = connection_pool(self.account_id)
# Metric flags for sync performance
self.is_initial_sync = False
self.is_first_sync = False
self.is_first_message = False
with session_scope() as db_session:
account = Account.get(self.account_id, db_session)
self.namespace_id = account.namespace.id
assert self.namespace_id is not None, "namespace_id is None"
folder = Folder.get(self.folder_id, db_session)
if folder:
self.is_initial_sync = folder.initial_sync_end is None
self.is_first_sync = folder.initial_sync_start is None
self.is_first_message = self.is_first_sync
self.state_handlers = {
'initial': self.initial_sync,
'initial uidinvalid': self.resync_uids,
'poll': self.poll,
'poll uidinvalid': self.resync_uids,
}
Greenlet.__init__(self)
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
self.folder_id,
self.folder_name,
email_address,
self.provider_name)
示例5: __init__
def __init__(self, account_id, namespace_id, email_address, folder_id,
folder_name, provider_name, poll_frequency=1,
scope=None):
self.account_id = account_id
self.namespace_id = namespace_id
self.poll_frequency = poll_frequency
self.scope = scope
self.log = logger.new(account_id=account_id)
self.shutdown = event.Event()
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
folder_id,
folder_name,
email_address,
provider_name)
Greenlet.__init__(self)
示例6: FolderSyncEngine
class FolderSyncEngine(Greenlet):
"""Base class for a per-folder IMAP sync engine."""
def __init__(self, account_id, namespace_id, folder_name, folder_id,
email_address, provider_name, syncmanager_lock):
bind_context(self, 'foldersyncengine', account_id, folder_id)
self.account_id = account_id
self.namespace_id = namespace_id
self.folder_name = folder_name
self.folder_id = folder_id
if self.folder_name.lower() == 'inbox':
self.poll_frequency = INBOX_POLL_FREQUENCY
else:
self.poll_frequency = DEFAULT_POLL_FREQUENCY
self.syncmanager_lock = syncmanager_lock
self.state = None
self.provider_name = provider_name
self.last_fast_refresh = None
self.conn_pool = connection_pool(self.account_id)
# Metric flags for sync performance
self.is_initial_sync = False
self.is_first_sync = False
self.is_first_message = False
with session_scope(self.namespace_id) as db_session:
folder = Folder.get(self.folder_id, db_session)
if folder:
self.is_initial_sync = folder.initial_sync_end is None
self.is_first_sync = folder.initial_sync_start is None
self.is_first_message = self.is_first_sync
self.state_handlers = {
'initial': self.initial_sync,
'initial uidinvalid': self.resync_uids,
'poll': self.poll,
'poll uidinvalid': self.resync_uids,
}
Greenlet.__init__(self)
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
self.folder_id,
self.folder_name,
email_address,
self.provider_name)
def _run(self):
# Bind greenlet-local logging context.
self.log = log.new(account_id=self.account_id, folder=self.folder_name,
provider=self.provider_name)
# eagerly signal the sync status
self.heartbeat_status.publish()
return retry_with_logging(self._run_impl, account_id=self.account_id,
provider=self.provider_name, logger=log)
def _run_impl(self):
try:
saved_folder_status = self._load_state()
except IntegrityError:
# The state insert failed because the folder ID ForeignKey
# was no longer valid, ie. the folder for this engine was deleted
# while we were starting up.
# Exit the sync and let the monitor sort things out.
log.info("Folder state loading failed due to IntegrityError",
folder_id=self.folder_id, account_id=self.account_id)
raise MailsyncDone()
# NOTE: The parent ImapSyncMonitor handler could kill us at any
# time if it receives a shutdown command. The shutdown command is
# equivalent to ctrl-c.
while True:
old_state = self.state
try:
self.state = self.state_handlers[old_state]()
self.heartbeat_status.publish(state=self.state)
except UidInvalid:
self.state = self.state + ' uidinvalid'
self.heartbeat_status.publish(state=self.state)
except FolderMissingError:
# Folder was deleted by monitor while its sync was running.
# TODO: Monitor should handle shutting down the folder engine.
log.info('Folder disappeared. Stopping sync.',
account_id=self.account_id,
folder_name=self.folder_name,
folder_id=self.folder_id)
raise MailsyncDone()
except ValidationError as exc:
log.error('Error authenticating; stopping sync', exc_info=True,
account_id=self.account_id, folder_id=self.folder_id,
logstash_tag='mark_invalid')
with session_scope(self.namespace_id) as db_session:
account = db_session.query(Account).get(self.account_id)
account.mark_invalid()
account.update_sync_error(str(exc))
raise MailsyncDone()
# State handlers are idempotent, so it's okay if we're
# killed between the end of the handler and the commit.
if self.state != old_state:
#.........这里部分代码省略.........
示例7: FolderSyncEngine
class FolderSyncEngine(Greenlet):
"""Base class for a per-folder IMAP sync engine."""
def __init__(self, account_id, folder_name, folder_id, email_address,
provider_name, poll_frequency, syncmanager_lock,
refresh_flags_max, retry_fail_classes):
bind_context(self, 'foldersyncengine', account_id, folder_id)
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.provider_name = provider_name
self.is_initial_sync = False
self.is_first_sync = False
with mailsync_session_scope() as db_session:
account = db_session.query(Account).get(self.account_id)
self.throttled = account.throttled
self.namespace_id = account.namespace.id
assert self.namespace_id is not None, "namespace_id is None"
folder = db_session.query(Folder).get(self.folder_id)
if folder:
self.is_initial_sync = folder.initial_sync_end is None
self.is_first_sync = folder.initial_sync_start is None
self.state_handlers = {
'initial': self.initial_sync,
'initial uidinvalid': self.resync_uids,
'poll': self.poll,
'poll uidinvalid': self.resync_uids,
'finish': lambda self: 'finish',
}
Greenlet.__init__(self)
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
self.folder_id,
self.folder_name,
email_address,
self.provider_name)
def _run(self):
# Bind greenlet-local logging context.
self.log = log.new(account_id=self.account_id, folder=self.folder_name)
# eagerly signal the sync status
self.heartbeat_status.publish()
return retry_and_report_killed(self._run_impl,
account_id=self.account_id,
folder_name=self.folder_name,
logger=log,
fail_classes=self.retry_fail_classes)
def _run_impl(self):
# We defer initializing the pool to here so that we'll retry if there
# are any errors (remote server 503s or similar) when initializing it.
self.conn_pool = connection_pool(self.account_id)
try:
saved_folder_status = self._load_state()
except IntegrityError:
# The state insert failed because the folder ID ForeignKey
# was no longer valid, ie. the folder for this engine was deleted
# while we were starting up.
# Exit the sync and let the monitor sort things out.
log.info("Folder state loading failed due to IntegrityError",
folder_id=self.folder_id, account_id=self.account_id)
raise MailsyncDone()
# NOTE: The parent ImapSyncMonitor handler could kill us at any
# time if it receives a shutdown command. The shutdown command is
# equivalent to ctrl-c.
while True:
old_state = self.state
try:
self.state = self.state_handlers[old_state]()
self.heartbeat_status.publish(state=self.state)
except UidInvalid:
self.state = self.state + ' uidinvalid'
self.heartbeat_status.publish(state=self.state)
except FolderMissingError:
# Folder was deleted by monitor while its sync was running.
# TODO: Monitor should handle shutting down the folder engine.
log.info('Folder disappeared: {}. Stopping sync.'.format(
self.folder_name), account_id=self.account_id,
folder_id=self.folder_id)
raise MailsyncDone()
except ValidationError:
log.error('Error authenticating; stopping sync', exc_info=True,
account_id=self.account_id, folder_id=self.folder_id)
raise MailsyncDone()
# State handlers are idempotent, so it's okay if we're
# killed between the end of the handler and the commit.
if self.state != old_state:
# Don't need to re-query, will auto refresh on re-associate.
with mailsync_session_scope() as db_session:
#.........这里部分代码省略.........
示例8: setup_heartbeats
def setup_heartbeats(self):
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
self.folder_id,
self.folder_name,
self.email_address,
self.provider_name)
示例9: BaseSyncMonitor
class BaseSyncMonitor(Greenlet):
"""
Abstracted sync monitor, based on BaseMailSyncMonitor but not mail-specific
Subclasses should run
bind_context(self, 'mailsyncmonitor', account.id)
poll_frequency : int
How often to check for commands.
retry_fail_classes : list
Exceptions to *not* retry on.
"""
def __init__(self, account_id, namespace_id, email_address, folder_id,
folder_name, provider_name, poll_frequency=1,
scope=None):
self.account_id = account_id
self.namespace_id = namespace_id
self.poll_frequency = poll_frequency
self.scope = scope
self.log = logger.new(account_id=account_id)
self.shutdown = event.Event()
self.heartbeat_status = HeartbeatStatusProxy(self.account_id,
folder_id,
folder_name,
email_address,
provider_name)
Greenlet.__init__(self)
def _run(self):
# Bind greenlet-local logging context.
self.log = self.log.new(account_id=self.account_id)
return retry_with_logging(self._run_impl, account_id=self.account_id,
logger=self.log)
def _run_impl(self):
# Return true/false based on whether the greenlet succeeds or throws
# and error. Note this is not how the mailsync monitor works
try:
while True:
# Check to see if this greenlet should exit
if self.shutdown.is_set():
self._cleanup()
return False
try:
self.sync()
self.heartbeat_status.publish(state='poll')
# If we get a connection or API permissions error, then sleep
# 2x poll frequency.
except ConnectionError:
self.log.error('Error while polling', exc_info=True)
self.heartbeat_status.publish(state='poll error')
sleep(self.poll_frequency)
sleep(self.poll_frequency)
except ValidationError:
# Bad account credentials; exit.
self.log.error('Error while establishing the connection',
account_id=self.account_id,
exc_info=True, logstash_tag='mark_invalid')
self._cleanup()
with session_scope(self.namespace_id) as db_session:
account = db_session.query(Account).get(self.account_id)
account.mark_invalid(scope=self.scope)
return False
def sync(self):
""" Subclasses should override this to do work """
raise NotImplementedError
def _cleanup(self):
self.heartbeat_status.clear()