Esempio n. 1
0
    def run(self):
        """ Run the Daemon. Setup signal handler, task registry, scheduler,
        listener and executors. Runs the main control loop.
        """
        try:
            # setup signal handlers for shutdown or immediate termination
            signal(SIGINT, self.shutdown)
            signal(SIGTERM, self.terminate)

            registry.initialize()

            # create executors, listener and scheduler
            self.executor_pool = ThreadPool(1)
            self.scheduler = Scheduler(self.on_scheduled)
            self.listener = get_listener()

            self.scheduler.start()
            self.reload_schedule()

            while True:
                try:
                    conn = self.listener.accept()
                except socket.error as exc:
                    # connection closed
                    if exc.errno in (errno.EINTR, errno.EBADF):
                        logger.info(
                            "Listener interrupted. Exiting main control loop."
                        )
                        break
                    else:
                        raise

                command = None
                try:
                    logger.debug("Client connected: %s", conn)
                    message = conn.recv()
                    logger.debug("Received message: %r", message)

                    command = message[0]
                    params = message[1:]

                    if command == "reload":
                        self.reload_schedule()

                    elif command == "restart":
                        job = models.Job.objects.get(id=params[0])
                        logger.info("Restarting job '%s'" % job)
                        self.executor_pool.apply_async(
                            registry.run, [job], job.arguments
                        )
                    elif command == "abort":
                        pass
                        # TODO: implement
                except Exception as exc:
                    logger.exception("Daemon command %s failed." % command)

        finally:
            self.shutdown()
Esempio n. 2
0
    def handle(self, *args, **options):
        registry.initialize()
        self.verbosity = options.get("verbosity", 1)
        if self.require_group:
            # self.authorize(self.require_group)
            pass

        self.info(
            "User '%s' is running command '%s' with "
            "arguments %r and options %r" %
            (self.get_user_name(), self.get_command_name(), args, options))
        return self.handle_authorized(*args, **options)
Esempio n. 3
0
    def handle(self, *args, **options):
        registry.initialize()
        self.verbosity = options.get("verbosity", 1)
        if self.require_group:
            # self.authorize(self.require_group)
            pass

        self.info(
            "User '%s' is running command '%s' with "
            "arguments %r and options %r" % (
                self.get_user_name(), self.get_command_name(),
                args, options
            )
        )
        return self.handle_authorized(*args, **options)
Esempio n. 4
0
    def handle_collection(self, collection, *args, **options):
        output = options["output"]
        registry.initialize()

        try:
            filename = registry.run("export",
                                    mission=collection.mission,
                                    file_type=collection.file_type,
                                    filename=output,
                                    configuration=options["configuration"],
                                    data=options["data"])
            print "Exported collection %s to %s" % (collection, filename)
        except Exception as exc:
            raise CommandError(
                "Failed to export collection %s to %s. Error was: %s" %
                (collection, options["output"], exc))
Esempio n. 5
0
    def handle_collection(self, collection, *args, **options):
        output = options["output"]
        registry.initialize()

        try:
            filename = registry.run(
                "export",
                mission=collection.mission,
                file_type=collection.file_type,
                filename=output,
                configuration=options["configuration"],
                data=options["data"],
            )
            print "Exported collection %s to %s" % (collection, filename)
        except Exception as exc:
            raise CommandError(
                "Failed to export collection %s to %s. Error was: %s" % (collection, options["output"], exc)
            )