Esempio n. 1
0
    def startService(self):
        log.msg("Starting VumiService")
        vumi_options = {}
        for opt in [i[0] for i in Options.optParameters]:
            vumi_options[opt] = self.options.pop(opt)

        worker_creator = WorkerCreator(vumi_options)

        # We need an initial worker. This would either be a normal
        # worker class (if we're using the old one-per-process model)
        # or a worker that loads new workers.
        worker_class = self.options.pop("worker-class")
        if worker_class is None:
            # fallback to deprecated --worker_class option
            worker_class = self.options.pop('worker_class')

        if not worker_class:
            raise VumiError("please specify --worker-class")

        config = {}
        # load the config file if specified
        config_file = self.options.pop('config')
        if config_file:
            with file(config_file, 'r') as stream:
                config.update(yaml.safe_load(stream))

        # add options set with --set-option
        config.update(self.options.set_options)

        self.worker = worker_creator.create_worker(worker_class, config)
        return self.worker.startService()
Esempio n. 2
0
def main(options):
    worker_creator = WorkerCreator(options.vumi_options)
    service = worker_creator.create_worker_by_class(
        ContactMigrationWorker, options.get_vumigo_config())
    service.startService()

    worker = yield ContactMigrationWorker.WORKER_QUEUE.get()
    yield worker.migrate_contacts_for_account(options['user-account-key'])
    reactor.stop()
Esempio n. 3
0
def main(options):
    worker_creator = WorkerCreator(options.vumi_options)
    service = worker_creator.create_worker_by_class(
        ContactMigrationWorker, options.get_vumigo_config())
    service.startService()

    worker = yield ContactMigrationWorker.WORKER_QUEUE.get()
    yield worker.migrate_contacts_for_account(options['user-account-key'])
    reactor.stop()
Esempio n. 4
0
def main(options):
    worker_creator = WorkerCreator(options.vumi_options)
    service = worker_creator.create_worker_by_class(
        JsBoxSendWorker, options.get_vumigo_config())
    service.startService()

    worker = yield JsBoxSendWorker.WORKER_QUEUE.get()
    yield worker.send_jsbox(
        options['user-account-key'], options['conversation-key'],
        options['hz'], options['exclude-addresses-file'])
    reactor.stop()
Esempio n. 5
0
def main(options):
    worker_creator = WorkerCreator(options.vumi_options)
    service = worker_creator.create_worker_by_class(
        JsBoxSendWorker, options.get_vumigo_config())
    service.startService()

    worker = yield JsBoxSendWorker.WORKER_QUEUE.get()
    yield worker.send_jsbox(options['user-account-key'],
                            options['conversation-key'], options['hz'],
                            options['exclude-addresses-file'])
    reactor.stop()
Esempio n. 6
0
 def create_worker(self):
     config = self.config
     worker_creator = WorkerCreator({
         'hostname': config.amqp_hostname,
         'port': config.amqp_port,
         'username': config.amqp_username,
         'password': config.amqp_password,
         'vhost': config.amqp_vhost,
         'specfile': config.amqp_spec,
     })
     return worker_creator.create_worker_by_class(
         MetricWorker, {'prefix': config.prefix})
Esempio n. 7
0
def main(options):
    verbose = options['verbose']

    worker_creator = WorkerCreator(options.vumi_options)
    worker_creator.create_worker_by_class(MessageInjector, options)

    in_file = sys.stdin
    out_file = sys.stdout if verbose else None

    worker = yield MessageInjector.WORKER_QUEUE.get()
    yield worker.process_file(in_file, out_file)
    reactor.stop()
Esempio n. 8
0
def main(options):
    verbose = options['verbose']

    worker_creator = WorkerCreator(options.vumi_options)
    worker_creator.create_worker_by_class(
        MessageInjector, options)

    in_file = sys.stdin
    out_file = sys.stdout if verbose else None

    worker = yield MessageInjector.WORKER_QUEUE.get()
    yield worker.process_file(in_file, out_file)
    reactor.stop()
Esempio n. 9
0
def main(options):
    vumi_options = {}
    verbose = options['verbose']
    for opt in [i[0] for i in Options.optParameters]:
        vumi_options[opt] = options.pop(opt)

    worker_creator = WorkerCreator(vumi_options)
    worker_creator.create_worker_by_class(
        MessageInjector, options)

    in_file = sys.stdin
    out_file = sys.stdout if verbose else None

    worker = yield MessageInjector.WORKER_QUEUE.get()
    yield worker.process_file(in_file, out_file)
    reactor.stop()
Esempio n. 10
0
    def makeService(self, options):
        sentry_dsn = options.vumi_options.pop('sentry', None)
        class_name = options.worker_class.rpartition('.')[2].lower()
        logger_name = options.worker_config.get('worker_name', class_name)
        system_id = options.vumi_options.get('system-id', 'global')
        worker_id = generate_worker_id(system_id, logger_name)

        worker_creator = WorkerCreator(options.vumi_options)
        worker = worker_creator.create_worker(options.worker_class,
                                              options.worker_config)

        if sentry_dsn is not None:
            sentry_service = SentryLoggerService(sentry_dsn, logger_name,
                                                 worker_id)
            worker.addService(sentry_service)

        return worker
Esempio n. 11
0
    def makeService(self, options):
        sentry_dsn = options.vumi_options.pop('sentry', None)
        class_name = options.worker_class.rpartition('.')[2].lower()
        logger_name = options.worker_config.get('worker_name', class_name)
        system_id = options.vumi_options.get('system-id', 'global')
        worker_id = generate_worker_id(system_id, logger_name)

        worker_creator = WorkerCreator(options.vumi_options)
        worker = worker_creator.create_worker(options.worker_class,
                                              options.worker_config)

        if sentry_dsn is not None:
            sentry_service = SentryLoggerService(sentry_dsn,
                                                 logger_name,
                                                 worker_id)
            worker.addService(sentry_service)

        return worker
Esempio n. 12
0
 def startService(self):
     log.msg("Starting VumiService")
     host = self.options.pop('hostname')
     port = self.options.pop('port')
     # the worker creator starts workers, give it what class you 
     # want to start and what options you want to pass along
     worker_class_name = self.options.pop("worker_class")
     if not worker_class_name:
         raise VumiError, "please specify --worker_class"
     
     # load the config file if specified
     config_file = self.options.pop('config')
     if config_file:
         with file(config_file, 'r') as stream:
             self.options.update({
                 'config': yaml.load(stream)
             })
     
     worker_class = load_class_by_string(worker_class_name)
     creator = WorkerCreator(worker_class, **self.options)
     # after that you connect it to the AMQP server
     creator.connectTCP(host, port)
Esempio n. 13
0
 def load_worker(self, worker_class, config, vumi_options_override=None):
     options = deepcopy(self.vumi_options)
     if vumi_options_override:
         options.update(vumi_options_override)
     creator = WorkerCreator(options)
     creator.create_worker(worker_class, config)
Esempio n. 14
0
 def makeService(self, options):
     worker_creator = WorkerCreator(options.vumi_options)
     worker = worker_creator.create_worker(options.worker_class,
                                           options.worker_config)
     return worker
Esempio n. 15
0
def run_bench(loops):
    opts = VumiOptions()
    opts.postOptions()
    worker_creator = WorkerCreator(opts.vumi_options)

    app = worker_creator.create_worker_by_class(
        BenchApp, {
            "transport_name": "dummy",
            "javascript": """
            api.on_inbound_message = function(command) {
                this.request('outbound.reply_to', {
                    content: 'reply',
                    in_reply_to: command.msg.message_id,
                },
                function (reply) {
                    this.done();
                });
            };
        """,
            "sandbox": {
                'log': {
                    'cls': 'vumi.application.sandbox.LoggingResource',
                },
                'outbound': {
                    'cls': 'vumi.application.sandbox.OutboundResource',
                },
            },
        })

    transport = worker_creator.create_worker_by_class(
        BenchTransport, {
            "transport_name": "dummy",
        })

    yield transport.startService()
    log.msg("Waiting for transport ...")
    yield BenchTransport.WORKER_QUEUE.get()

    yield app.startService()
    log.msg("Waiting for worker ...")
    yield BenchApp.WORKER_QUEUE.get()

    print "Starting %d loops ..." % (loops, )
    timer = Timer()
    for i in range(loops):
        with timer:
            transport.publish_message(
                content="Hi!",
                to_addr="+1234",
                from_addr="+5678",
                transport_type="ussd",
            )
            reply = yield transport.message_queue.get()
            log.msg("Reply ID: %s" % reply['message_id'])

    print "Total time: %.2f" % timer.total()
    print "Time per message: %g" % timer.mean()
    print "  max: %g, min: %g" % (timer.max(), timer.min())
    print "  loops: %d" % timer.loops()

    yield transport.stopService()
    yield app.stopService()
    reactor.stop()
Esempio n. 16
0
 def makeService(self, options):
     worker_creator = WorkerCreator(options.vumi_options)
     worker = worker_creator.create_worker(options.worker_class,
                                           options.worker_config)
     return worker
Esempio n. 17
0
 def _create_worker(self, cls_name, config):
     creator = WorkerCreator(self.options)
     worker = creator.create_worker(cls_name, config)
     return worker
Esempio n. 18
0
def run_bench(loops):
    opts = VumiOptions()
    opts.postOptions()
    worker_creator = WorkerCreator(opts.vumi_options)

    app = worker_creator.create_worker_by_class(BenchApp, {
        "transport_name": "dummy",
        "javascript": """
            api.on_inbound_message = function(command) {
                this.request('outbound.reply_to', {
                    content: 'reply',
                    in_reply_to: command.msg.message_id,
                },
                function (reply) {
                    this.done();
                });
            };
        """,
        "sandbox": {
            'log': {
                'cls': 'vumi.application.sandbox.LoggingResource',
            },
            'outbound': {
                'cls': 'vumi.application.sandbox.OutboundResource',
            },
        },
    })

    transport = worker_creator.create_worker_by_class(BenchTransport, {
        "transport_name": "dummy",
    })

    yield transport.startService()
    log.msg("Waiting for transport ...")
    yield BenchTransport.WORKER_QUEUE.get()

    yield app.startService()
    log.msg("Waiting for worker ...")
    yield BenchApp.WORKER_QUEUE.get()

    print "Starting %d loops ..." % (loops,)
    timer = Timer()
    for i in range(loops):
        with timer:
            transport.publish_message(
                content="Hi!",
                to_addr="+1234",
                from_addr="+5678",
                transport_type="ussd",
            )
            reply = yield transport.message_queue.get()
            log.msg("Reply ID: %s" % reply['message_id'])

    print "Total time: %.2f" % timer.total()
    print "Time per message: %g" % timer.mean()
    print "  max: %g, min: %g" % (timer.max(), timer.min())
    print "  loops: %d" % timer.loops()

    yield transport.stopService()
    yield app.stopService()
    reactor.stop()