예제 #1
0
app = flask.Flask(__name__)

app.config.from_object(rq_dashboard.default_settings)
app.register_blueprint(rq_dashboard.blueprint, url_prefix="/rq")
app.config["REDIS_URL"] = utils.get_redis_url()
app.config["RQ_POLL_INTERVAL"] = 10000  # ms
sentry = raven.contrib.flask.Sentry(app, dsn=config.SENTRY_URL)

# TODO(sileht): Make the ring dynamic
global RING
nodes = []
for fqdn, w in sorted(config.TOPOLOGY.items()):
    nodes.extend(map(lambda x: "%s-%003d" % (fqdn, x), range(w)))

RING = uhashring.HashRing(nodes=nodes)


def get_queue(slug, subscription):
    global RING
    name = "%s-%s" % (RING.get_node(slug),
                      "high" if subscription["subscribed"] else "low")
    return rq.Queue(name, connection=utils.get_redis_for_rq())


def authentification():  # pragma: no cover
    # Only SHA1 is supported
    header_signature = flask.request.headers.get('X-Hub-Signature')
    if header_signature is None:
        LOG.warning("Webhook without signature")
        flask.abort(403)
예제 #2
0
import uhashring

from mergify_engine import backports
from mergify_engine import branch_protection
from mergify_engine import branch_updater
from mergify_engine import check_api
from mergify_engine import config
from mergify_engine import mergify_pull
from mergify_engine import rules
from mergify_engine import utils
from mergify_engine.worker import app

LOG = daiquiri.getLogger(__name__)

RING = uhashring.HashRing(nodes=list(
    itertools.chain.from_iterable(
        map(lambda x: "worker-%003d@%s" % (x, fqdn), range(w))
        for fqdn, w in sorted(config.TOPOLOGY.items()))))


@app.task
def handle(installation_id, installation_token, subscription, branch_rules,
           event_type, data, event_pull_raw):
    # NOTE(sileht): The processor is not concurrency safe, so a repo is always
    # sent to the same worker.
    # This work in coordination with app.conf.worker_direct = True that creates
    # a dedicated queue on exchange c.dq2 for each worker
    routing_key = RING.get_node(data["repository"]["full_name"])
    LOG.info("Sending repo %s to %s", data["repository"]["full_name"],
             routing_key)
    _handle.s(installation_id, installation_token, subscription, branch_rules,
              event_type, data,
예제 #3
0
 def __init__(self, server_list):
     self.server_list = server_list
     self.ring = uhashring.HashRing(self.server_list)
예제 #4
0
def get_ring(topology, kind):
    return uhashring.HashRing(nodes=list(
        itertools.chain.from_iterable(
            map(lambda x: "worker-%s-%003d@%s" % (kind, x, fqdn), range(w))
            for fqdn, w in sorted(topology.items()))))