Пример #1
0
class Controller(Parent):

    def models(self):
        self.workers = Worker(self.config)

    # BELOW THIS LINE ARE ALL CONTROLLER ACTIONS

    def new(self, body, resp):
        worker = self.workers.new()

        machine = ProcHandler(self.config, Writer(self.config))
        machine.start()

        worker.CONTROLQUEUE = machine.stopqueue
        worker.OUTPUTQUEUE = machine.subproc.queue

        self.workers.save(worker)

        resp.respond(worker.OUTPUTQUEUE)

    def delete(self, body, resp):
        worker = self.workers.find(body.data)
        pub = SimplePublisher(
            ''. self.config['Rabbit']['host'],
            self.config['Rabbit']['username'],
            self.config['Rabbit']['passwords'])
        pub.publish_msg(self, 'STOP', work.CONTROLQUEUE)

        resp.respond('DELETED')
Пример #2
0
class Controller(Parent):

    def models(self):
        self.workers = Worker(self.config)

    # BELOW THIS LINE ARE ALL CONTROLLER ACTIONS

    def get_all(self, msg, resp):
        # find all currently running alert
        workers = self.workers.findAll()
        response = {}
        for w in workers:
            response[w.UUID] = w.to_hash()

        resp.respond(response)

    def new(self, msg, resp):
        worker = self.workers.new()

        sender = RPCSender(self.config)
        r = sender.channel.queue_declare()
        q = r.method.queue

        machine = ProcHandler(
            self.config,
            Alerter(
                self.config,
                msg['data']['query'],
                msg['data']['time'],
                msg['data']['quantity'],
                msg['data']['message'],
                msg['data']['user']),
            q)
        machine.start()

        req = json.loads(sender.send_request(
            'GET',
            'hive',
            {'variables': ['uuid']},
            '',
            '',
            key=q))

        print req

        worker.UUID = req['uuid']
        worker.CONTROLQUEUE = q
        worker.QUERY = msg['data']['query']
        worker.TIME = msg['data']['time']
        worker.QUANTITY = msg['data']['quantity']
        worker.MESSAGE = msg['data']['message']

        self.workers.save(worker)

        resp.respond({worker.UUID: worker.to_hash()})

    def delete(self, body, resp):
        worker = self.workers.find(body.data)
        pub = SimplePublisher(
            ''. self.config['Rabbit']['host'],
            self.config['Rabbit']['username'],
            self.config['Rabbit']['passwords'])
        pub.publish_msg(self, 'STOP', work.CONTROLQUEUE)

        resp.respond('DELETED')