예제 #1
0
파일: run.py 프로젝트: dmc2015/moxie
    def run(self, job, why, cmd=None):
        self.containers = EventService.resolve(
            "moxie.cores.container.ContainerService")
        self.database = EventService.resolve(
            "moxie.cores.database.DatabaseService")
        self.logger = EventService.resolve("moxie.cores.log.LogService")
        self.alert = EventService.resolve("moxie.cores.alert.AlertService")

        job = yield from self.database.job.get(job)
        if job is None:
            raise ValueError("No such job name!")

        with (yield from self.lock):
            try:
                good = yield from self.database.job.take(job.name)
            except ValueError:
                yield from self.log('error', job=job.name, error="already active")
                return

            yield from self.alert.starting(job.name)
            yield from self.log('starting', job=job.name, why=why)
            yield from self._bringup(job)
            yield from self._start(job)
            yield from self.alert.running(job.name)
            yield from self.log('started', job=job.name, why=why)
            yield from asyncio.sleep(5)  # Thrashing the disk is causing
예제 #2
0
파일: run.py 프로젝트: randyamiel/moxie
    def run(self, job, why, cmd=None):
        self.containers = EventService.resolve(
            "moxie.cores.container.ContainerService")
        self.database = EventService.resolve(
            "moxie.cores.database.DatabaseService")
        self.logger = EventService.resolve("moxie.cores.log.LogService")
        self.alert = EventService.resolve("moxie.cores.alert.AlertService")

        job = yield from self.database.job.get(job)
        if job is None:
            raise ValueError("No such job name!")

        with (yield from self.lock):
            try:
                good = yield from self.database.job.take(job.name)
            except ValueError:
                yield from self.log('error',
                                    job=job.name,
                                    error="already active")
                return

            yield from self.alert.starting(job.name)
            yield from self.log('starting', job=job.name, why=why)
            yield from self._bringup(job)
            yield from self._start(job)
            yield from self.alert.running(job.name)
            yield from self.log('started', job=job.name, why=why)
            yield from asyncio.sleep(5)  # Thrashing the disk is causing
예제 #3
0
파일: reap.py 프로젝트: dmc2015/moxie
    def __call__(self):
        self.database = EventService.resolve(
            "moxie.cores.database.DatabaseService")
        self.containers = EventService.resolve(
            "moxie.cores.container.ContainerService")
        self.logger = EventService.resolve("moxie.cores.log.LogService")
        self.run = EventService.resolve("moxie.cores.run.RunService")
        self.alert = EventService.resolve("moxie.cores.alert.AlertService")

        while True:
            jobs = (yield from self.database.job.list(Job.active == True))
            # yield from self.logger.log("reap", "Wakeup")
            for job in jobs:
                with (yield from self.run.lock):
                    yield from self.reap(job)
                    yield from asyncio.sleep(2)  # Thrashing the disk is causing
                    #                        massive issues in prod; this sucks.
            # yield from self.logger.log("reap", "Sleep")
            yield from asyncio.sleep(5)
예제 #4
0
    def __call__(self):
        self.database = EventService.resolve(
            "moxie.cores.database.DatabaseService")
        self.containers = EventService.resolve(
            "moxie.cores.container.ContainerService")
        self.logger = EventService.resolve("moxie.cores.log.LogService")
        self.run = EventService.resolve("moxie.cores.run.RunService")
        self.alert = EventService.resolve("moxie.cores.alert.AlertService")

        while True:
            jobs = (yield from self.database.job.list(Job.active == True))
            # yield from self.logger.log("reap", "Wakeup")
            for job in jobs:
                with (yield from self.run.lock):
                    yield from self.reap(job)
                    yield from asyncio.sleep(
                        2)  # Thrashing the disk is causing
                    #                        massive issues in prod; this sucks.
            # yield from self.logger.log("reap", "Sleep")
            yield from asyncio.sleep(5)
예제 #5
0
def run(bot, message: "message"):
    runner = EventService.resolve("moxie.cores.run.RunService")

    text = message.get("text", "")
    if text == "":
        yield from bot.post(message['channel'], "Invalid request")
        return

    elif text.strip().lower() == "fact":
        yield from bot.post(
            message['channel'], "<@{}>: {}".format(message['user'], get_fact()))
        return

    elif text.strip().lower() in ("yo", ":yo:"):
        yield from bot.post(
            message['channel'], "<@{}>: :yo:".format(message['user']))
        return

    cmd, arg = text.split(" ", 1)
    if cmd == "run":
        job = arg
        yield from bot.post(
            message['channel'], "<@{}>: Doing bringup of {}".format(
                message['user'], job))
        try:
            yield from runner.run(
                job,
                'slack from <@{}>'.format(message['user'])
            )
        except ValueError as e:
            yield from bot.post(
                message['channel'],
                "<@{user}>: Gah, {job} failed - {e}".format(
                    user=message['user'], e=e, job=job)
            )
            return

        yield from bot.post(message['channel'],
            "<@{user}>: job {job} online - {webroot}/container/{job}/".format(
                user=message['user'], webroot=WEB_ROOT, job=job))
예제 #6
0
def run(bot, message: "message"):
    runner = EventService.resolve("moxie.cores.run.RunService")

    text = message.get("text", "")
    if text == "":
        yield from bot.post(message['channel'], "Invalid request")
        return

    elif text.strip().lower() == "fact":
        yield from bot.post(message['channel'],
                            "<@{}>: {}".format(message['user'], get_fact()))
        return

    elif text.strip().lower() in ("yo", ":yo:"):
        yield from bot.post(message['channel'],
                            "<@{}>: :yo:".format(message['user']))
        return

    cmd, arg = text.split(" ", 1)
    if cmd == "run":
        job = arg
        yield from bot.post(
            message['channel'],
            "<@{}>: Doing bringup of {}".format(message['user'], job))
        try:
            yield from runner.run(job,
                                  'slack from <@{}>'.format(message['user']))
        except ValueError as e:
            yield from bot.post(
                message['channel'],
                "<@{user}>: Gah, {job} failed - {e}".format(
                    user=message['user'], e=e, job=job))
            return

        yield from bot.post(
            message['channel'],
            "<@{user}>: job {job} online - {webroot}/container/{job}/".format(
                user=message['user'], webroot=WEB_ROOT, job=job))