Esempio n. 1
0
    def handle(self, *args, **options):
        """
        Entry-point of the consumer
        """
        autodiscover()

        self.initialize_options(ObjectDict(options))

        self.logger.info(
            'Initializing consumer with options:\nlogfile: %s\ndelay: %s\nbackoff: %s\nthreads: %s'
            % (self.logfile, self.delay, self.backoff_factor, self.threads))

        self.logger.info('Loaded classes:\n%s' %
                         '\n'.join([klass for klass in registry._registry]))

        self.set_signal_handler()

        try:
            self.start()

            # it seems that calling self._shutdown.wait() here prevents the
            # signal handler from executing
            while not self._shutdown.is_set():
                self._shutdown.wait(.1)
        except:
            self.logger.error('error', exc_info=1)
            self.shutdown()

        self.logger.info('Shutdown...')
Esempio n. 2
0
    def handle(self, *args, **options):
        """
        Entry-point of the consumer
        """
        autodiscover()

        self.initialize_options(ObjectDict(options))

        self.logger.info(
            "Initializing consumer with options:\nlogfile: %s\ndelay: %s\nbackoff: %s\nthreads: %s"
            % (self.logfile, self.delay, self.backoff_factor, self.threads)
        )

        self.logger.info("Loaded classes:\n%s" % "\n".join([klass for klass in registry._registry]))

        self.set_signal_handler()

        try:
            self.start()

            # it seems that calling self._shutdown.wait() here prevents the
            # signal handler from executing
            while not self._shutdown.is_set():
                self._shutdown.wait(0.1)
        except:
            self.logger.error("error", exc_info=1)
            self.shutdown()

        self.logger.info("Shutdown...")
Esempio n. 3
0
    def handle(self, *args, **options):
        """
        Entry-point of the consumer -- in what might be a premature optimization,
        I've chosen to keep the code paths separate depending on whether the
        periodic command thread is started.
        """
        autodiscover()
        
        self.initialize_options(ObjectDict(options))
        
        self.logger.info('Initializing consumer with options:\nlogfile: %s\ndelay: %s\nbackoff: %s\nthreads: %s' % (
            self.logfile, self.delay, self.backoff_factor, self.threads))

        self.logger.info('Loaded classes:\n%s' % '\n'.join([
            klass for klass in registry._registry
        ]))
        
        try:
            if self.periodic_commands:
                self.run_with_periodic_commands()
            else:
                self.run_only_queue()
        except:
            self.logger.error('error', exc_info=1)
Esempio n. 4
0
    def handle(self, *args, **options):
        """
        Entry-point of the consumer -- in what might be a premature optimization,
        I've chosen to keep the code paths separate depending on whether the
        periodic command thread is started.
        """
        autodiscover()

        self.initialize_options(ObjectDict(options))

        self.logger.info(
            'Initializing consumer with options:\nlogfile: %s\ndelay: %s\nbackoff: %s\nthreads: %s'
            % (self.logfile, self.delay, self.backoff_factor, self.threads))

        self.logger.info('Loaded classes:\n%s' %
                         '\n'.join([klass for klass in registry._registry]))

        try:
            if self.periodic_commands:
                self.run_with_periodic_commands()
            else:
                self.run_only_queue()
        except:
            self.logger.error('error', exc_info=1)
    parser.add_option('--logfile', '-l', dest='logfile', default='',
        help='Destination for log file')
    parser.add_option('--no-periodic', '-n', dest='no_periodic', action='store_true',
        default=False, help='Do not enqueue periodic commands')
    parser.add_option('--threads', '-t', dest='threads', default=1,
        help='Number of worker threads, default = 1')
    return parser

if __name__ == '__main__':
    get_apps() # populate app cache

    parser = get_parser()
    (options, args) = parser.parse_args()
    
    if options.foreground:
        args = ['start']
    
    if not args:
        print "usage: %s start|stop|restart" % sys.argv[0]
        sys.exit(2)
    
    # load up all commands.py modules in the installed apps
    autodiscover()
    
    daemon = QueueDaemon(options)
    
    if not options.foreground:
        daemon.run_simple(args[0])
    else:
        daemon.run()
Esempio n. 6
0
    parser.add_option('--threads',
                      '-t',
                      dest='threads',
                      default=1,
                      help='Number of worker threads, default = 1')
    return parser


if __name__ == '__main__':
    get_apps()  # populate app cache

    parser = get_parser()
    (options, args) = parser.parse_args()

    if options.foreground:
        args = ['start']

    if not args:
        print "usage: %s start|stop|restart" % sys.argv[0]
        sys.exit(2)

    # load up all commands.py modules in the installed apps
    autodiscover()

    daemon = QueueDaemon(options)

    if not options.foreground:
        daemon.run_simple(args[0])
    else:
        daemon.run()