예제 #1
0
from phonon import get_logger, PHONON_NAMESPACE, TTL

import time

import phonon.lock
import phonon.nodelist
import phonon.connections

logger = get_logger(__name__)


class Reference(object):
    """
    Represents a reference to some resource in the network. Handles reference
    counting, dereferencing, locking/ownership, and maintaining whether or not
    resources were externally modified.

    This class also provides a layer of abstraction on failover and cleanup. In
    the event of total process failure; a reference on that process will expire
    and be subsequently detected/recovered by this class to the extent updates
    overlap.

    More in-depth:

    When a process acquires a `Reference` to a resource it attempts to lock
    that resource. It will block by default for a total of Process.BLOCKING_TIMEOUT
    seconds (defaults to 500s) before raising a Reference.AlreadyLocked
    exception

    That process/reference will attempt to connect to the backend, and retry
    until either successful completion of the task or python's maximum
예제 #2
0
파일: __init__.py 프로젝트: buzzfeed/phonon
import time

import uuid
import tornado.ioloop
import collections

from phonon import get_logger, PHONON_NAMESPACE
import phonon.client
import phonon.event


logger = get_logger(__name__)
connection = None


def get_ms():
    return int(time.time() * 1000.)


def s_to_ms(s):
    return int(s * 1000.)


class AsyncConn(phonon.event.EventMixin):

    HEARTBEAT_INTERVAL = 30  # Seconds
    HEARTBEAT_KEY = '{}.heartbeat'.format(phonon.PHONON_NAMESPACE)
    PROCESS_TTL = phonon.TTL * 0.5

    def __init__(self, redis_hosts, port=6379, db=1, ioloop=None):
        super(AsyncConn, self).__init__()