示例#1
0
#
# This file is part of pistil released under the MIT license.
# See the NOTICE for more information.

from pistil.arbiter import Arbiter
from pistil.worker import Worker


class MyWorker(Worker):

    def handle(self):
        print "hello worker 1 from %s" % self.name

class MyWorker2(Worker):

    def handle(self):
        print "hello worker 2 from %s" % self.name


if __name__ == '__main__':
    conf = {}

    specs = [
        (MyWorker, 30, "worker", {}, "w1"),
        (MyWorker2, 30, "worker", {}, "w2"),
        (MyWorker2, 30, "kill", {}, "w3")
    ]
    # launchh the arbiter
    arbiter = Arbiter(conf, specs)
    arbiter.run()
示例#2
0
            pass
        else:
            self.conn.poll()
            # It's for postgres < 9, without payload, so noftifies are just ONE
            # trigger
            self.fetch_events()
            while self.conn.notifies:
                self.conn.notifies.pop()

    def on_event(self, evt):
        raise NotImplementedError()


if __name__ == '__main__':

    class TestWorker(PgEventWorker):
        def on_event(self, evt):
            print "###### Event", self.pid, evt.channel, evt.payload

    conf = {
        "dsn": "dbname=pubsub",
        "channel": "test",
    }

    specs = [
        (TestWorker, 30, "worker", {}, "listener"),
    ]

    arbiter = Arbiter(conf, specs)
    arbiter.run()
示例#3
0
文件: hello.py 项目: stsai/pistil
# -*- coding: utf-8 -
#
# This file is part of pistil released under the MIT license.
# See the NOTICE for more information.

import time

from pistil.arbiter import Arbiter
from pistil.worker import Worker


class MyWorker(Worker):

    def handle(self):
        print "hello from worker n°%s" % self.pid


if __name__ == "__main__":
    conf = {}
    specs = [(MyWorker, 30, "worker", {}, "test")]
    a = Arbiter(conf, specs)
    a.run()
示例#4
0
文件: util.py 项目: Natim/redbarrel
def _run_server(args):
    logger.info("Serving on port %d..." % args.port)

    # loading the rbr to get the workers/arbiters
    from redbarrel.dsl import build_ast
    from redbarrel.dsl.runners import resolve_runner

    workers = {}
    arbiters = {}

    for path in args.path:
        with open(path) as f:
            ast = build_ast(f.read())

        for definition in ast:
            type_ = definition.type
            if type_ not in ('worker', 'arbiter'):
                continue

            name = definition[1]
            logger.info('Loading %s %r' % (type_, name))
            runner = resolve_runner(definition[2])
            if type_ == 'worker':
                workers[name] = runner
            else:
                arbiters[name] = runner

    # default arbiters and workers
    from redbarrel.server.arbiters import ARBITERS
    arbiters.update(ARBITERS)

    from redbarrel.server.workers import WORKERS
    workers.update(WORKERS)

    # now loading the workers and arbiters, given a config
    specs = []
    from pistil.arbiter import Arbiter

    conf = {"address": ("127.0.0.1", args.port),
            "debug": True,
            "memory": True,
            "num_workers": 1,  #args.workers,
            "path": args.path,
            "timeout": 9000  # XXXX
            }

    for name, num in args.workers:
        # is it an arbiter or a worker ?
        if name in arbiters:
            klass = arbiters[name]
            type_ = 'supervisor'
        elif name in workers:
            klass = workers[name]
            type_ = 'worker'
        else:
            raise ValueError(name)

        timeout = 90000  # XXX to be defined
        specs.append((klass, timeout, type_, {}, name))
        # XXX conf ?
        #

    arbiter = Arbiter(conf, specs)
    arbiter.run()
def _run_server(args):
    logger.info("Serving on port %d..." % args.port)

    # loading the rbr to get the workers/arbiters
    from redbarrel.dsl import build_ast
    from redbarrel.dsl.runners import resolve_runner

    workers = {}
    arbiters = {}

    for path in args.path:
        with open(path) as f:
            ast = build_ast(f.read())

        for definition in ast:
            type_ = definition.type
            if type_ not in ('worker', 'arbiter'):
                continue

            name = definition[1]
            logger.info('Loading %s %r' % (type_, name))
            runner = resolve_runner(definition[2])
            if type_ == 'worker':
                workers[name] = runner
            else:
                arbiters[name] = runner

    # default arbiters and workers
    from redbarrel.server.arbiters import ARBITERS
    arbiters.update(ARBITERS)

    from redbarrel.server.workers import WORKERS
    workers.update(WORKERS)

    # now loading the workers and arbiters, given a config
    specs = []
    from pistil.arbiter import Arbiter

    conf = {
        "address": ("127.0.0.1", args.port),
        "debug": True,
        "memory": True,
        "num_workers": 1,  #args.workers,
        "path": args.path,
        "timeout": 9000  # XXXX
    }

    for name, num in args.workers:
        # is it an arbiter or a worker ?
        if name in arbiters:
            klass = arbiters[name]
            type_ = 'supervisor'
        elif name in workers:
            klass = workers[name]
            type_ = 'worker'
        else:
            raise ValueError(name)

        timeout = 90000  # XXX to be defined
        specs.append((klass, timeout, type_, {}, name))
        # XXX conf ?
        #

    arbiter = Arbiter(conf, specs)
    arbiter.run()
示例#6
0
# -*- coding: utf-8 -
#
# This file is part of pistil released under the MIT license.
# See the NOTICE for more information.

import time

from pistil.arbiter import Arbiter
from pistil.worker import Worker


class MyWorker(Worker):
    def handle(self):
        print "hello from worker n°%s" % self.pid


if __name__ == "__main__":
    conf = {}
    specs = [(MyWorker, 30, "worker", {}, "test")]
    a = Arbiter(conf, specs)
    a.run()