コード例 #1
0
 def test_channel_filters(self):
     """
     Tests that the include/exclude logic works
     """
     # Include
     worker = Worker(None, only_channels=["yes.*", "maybe.*"])
     self.assertEqual(
         worker.apply_channel_filters(["yes.1", "no.1"]),
         ["yes.1"],
     )
     self.assertEqual(
         worker.apply_channel_filters(["yes.1", "no.1", "maybe.2", "yes"]),
         ["yes.1", "maybe.2"],
     )
     # Exclude
     worker = Worker(None, exclude_channels=["no.*", "maybe.*"])
     self.assertEqual(
         worker.apply_channel_filters(["yes.1", "no.1", "maybe.2", "yes"]),
         ["yes.1", "yes"],
     )
     # Both
     worker = Worker(None, exclude_channels=["no.*"], only_channels=["yes.*"])
     self.assertEqual(
         worker.apply_channel_filters(["yes.1", "no.1", "maybe.2", "yes"]),
         ["yes.1"],
     )
コード例 #2
0
ファイル: runworker.py プロジェクト: KIKUYA-Takumi/channels
 def handle(self, *args, **options):
     # Get the backend to use
     self.verbosity = options.get("verbosity", 1)
     self.logger = setup_logger('django.channels', self.verbosity)
     self.channel_layer = channel_layers[options.get("layer", DEFAULT_CHANNEL_LAYER)]
     # Check that handler isn't inmemory
     if self.channel_layer.local_only():
         raise CommandError(
             "You cannot span multiple processes with the in-memory layer. " +
             "Change your settings to use a cross-process channel layer."
         )
     # Check a handler is registered for http reqs
     # Serve static files if Django in debug mode
     if settings.DEBUG:
         self.channel_layer.router.check_default(http_consumer=StaticFilesConsumer())
     else:
         self.channel_layer.router.check_default()
     # Launch a worker
     self.logger.info("Running worker against channel layer %s", self.channel_layer)
     # Optionally provide an output callback
     callback = None
     if self.verbosity > 1:
         callback = self.consumer_called
     # Run the worker
     try:
         worker = Worker(
             channel_layer=self.channel_layer,
             callback=callback,
             only_channels=options.get("only_channels", None),
             exclude_channels=options.get("exclude_channels", None),
         )
         worker_ready.send(sender=worker)
         worker.run()
     except KeyboardInterrupt:
         pass
コード例 #3
0
ファイル: runworker.py プロジェクト: xinyvz/channels
 def handle(self, *args, **options):
     # Get the backend to use
     self.verbosity = options.get("verbosity", 1)
     self.logger = setup_logger('django.channels', self.verbosity)
     self.channel_layer = channel_layers[options.get(
         "layer", DEFAULT_CHANNEL_LAYER)]
     # Check that handler isn't inmemory
     if self.channel_layer.local_only():
         raise CommandError(
             "You cannot span multiple processes with the in-memory layer. "
             + "Change your settings to use a cross-process channel layer.")
     # Check a handler is registered for http reqs
     # Serve static files if Django in debug mode
     if settings.DEBUG:
         self.channel_layer.router.check_default(
             http_consumer=StaticFilesConsumer())
     else:
         self.channel_layer.router.check_default()
     # Launch a worker
     self.logger.info("Running worker against channel layer %s",
                      self.channel_layer)
     # Optionally provide an output callback
     callback = None
     if self.verbosity > 1:
         callback = self.consumer_called
     # Run the worker
     try:
         Worker(
             channel_layer=self.channel_layer,
             callback=callback,
             only_channels=options.get("only_channels", None),
             exclude_channels=options.get("exclude_channels", None),
         ).run()
     except KeyboardInterrupt:
         pass
コード例 #4
0
 def handle(self, *args, **options):
     # Get the backend to use
     self.verbosity = options.get("verbosity", 1)
     self.logger = setup_logger('django.channels', self.verbosity)
     channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
     if channel_backend.local_only:
         raise CommandError(
             "You have a process-local channel backend configured, and so cannot run separate workers.\n"
             "Configure a network-based backend in CHANNEL_BACKENDS to use this command."
         )
     # Check a handler is registered for http reqs
     if not channel_backend.registry.consumer_for_channel("http.request"):
         # Register the default one
         channel_backend.registry.add_consumer(UrlConsumer(),
                                               ["http.request"])
     # Launch a worker
     self.logger.info("Running worker against backend %s", channel_backend)
     # Optionally provide an output callback
     callback = None
     if self.verbosity > 1:
         callback = self.consumer_called
     # Run the worker
     try:
         Worker(channel_backend=channel_backend, callback=callback).run()
     except KeyboardInterrupt:
         pass
コード例 #5
0
 def handle(self, *args, **options):
     # Get the backend to use
     self.verbosity = options.get("verbosity", 1)
     # Get the channel layer they asked for (or see if one isn't configured)
     if "layer" in options:
         self.channel_layer = get_channel_layer(options["layer"])
     else:
         self.channel_layer = get_channel_layer()
     if self.channel_layer is None:
         raise CommandError(
             "You do not have any CHANNEL_LAYERS configured.")
     # Run the worker
     self.logger = setup_logger("django.channels", self.verbosity)
     self.logger.info("Running worker for channels %s", options["channels"])
     worker = Worker(
         application=get_default_application(),
         channels=options["channels"],
         channel_layer=self.channel_layer,
     )
     worker.run()
コード例 #6
0
 def run(self):
     self.logger.debug("Worker thread running")
     worker = Worker(channel_layer=self.channel_layer,
                     signal_handlers=False)
     worker.ready()
     worker.run()
     self.logger.debug("Worker thread exited")
コード例 #7
0
def main():
    channel_names = []
    for workers in (
            kocherga.email.channels.workers,
            kocherga.events.channels.workers,
            kocherga.telegram.channels.workers,
            kocherga.ratio.channels.workers,
            kocherga.slack.channels.workers,
    ):
        channel_names += workers.keys()

    logger.info(f"Starting worker for channels {channel_names}")
    Worker(
        application=get_default_application(),
        channels=channel_names,
        channel_layer=get_channel_layer(),
    ).run()
コード例 #8
0
ファイル: runworker.py プロジェクト: sonthonaxrk/channels
 def handle(self, *args, **options):
     # Get the backend to use
     channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
     if channel_backend.local_only:
         raise CommandError(
             "You have a process-local channel backend configured, and so cannot run separate workers.\n"
             "Configure a network-based backend in CHANNEL_BACKENDS to use this command."
         )
     # Launch a worker
     self.stdout.write("Running worker against backend %s" %
                       channel_backend)
     # Optionally provide an output callback
     callback = None
     if options.get("verbosity", 1) > 1:
         callback = self.consumer_called
     # Run the worker
     try:
         Worker(channel_backend=channel_backend, callback=callback).run()
     except KeyboardInterrupt:
         pass
コード例 #9
0
ファイル: runworker.py プロジェクト: hj3938/channels
 def handle(self, *args, **options):
     # Get the backend to use
     self.verbosity = options.get("verbosity", 1)
     self.logger = setup_logger('django.channels', self.verbosity)
     channel_layer = channel_layers[DEFAULT_CHANNEL_LAYER]
     # Check a handler is registered for http reqs
     if not channel_layer.registry.consumer_for_channel("http.request"):
         # Register the default one
         channel_layer.registry.add_consumer(ViewConsumer(),
                                             ["http.request"])
     # Launch a worker
     self.logger.info("Running worker against backend %s",
                      channel_layer.alias)
     # Optionally provide an output callback
     callback = None
     if self.verbosity > 1:
         callback = self.consumer_called
     # Run the worker
     try:
         Worker(channel_layer=channel_layer, callback=callback).run()
     except KeyboardInterrupt:
         pass
コード例 #10
0
 def handle(self, *args, **options):
     # Get the backend to use
     self.verbosity = options.get("verbosity", 1)
     self.logger = setup_logger('django.channels', self.verbosity)
     self.channel_layer = channel_layers[DEFAULT_CHANNEL_LAYER]
     # Check that handler isn't inmemory
     if self.channel_layer.local_only():
         raise CommandError(
             "You cannot span multiple processes with the in-memory layer. "
             + "Change your settings to use a cross-process channel layer.")
     # Check a handler is registered for http reqs
     self.channel_layer.registry.check_default()
     # Launch a worker
     self.logger.info("Running worker against backend %s",
                      self.channel_layer)
     # Optionally provide an output callback
     callback = None
     if self.verbosity > 1:
         callback = self.consumer_called
     # Run the worker
     try:
         Worker(channel_layer=self.channel_layer, callback=callback).run()
     except KeyboardInterrupt:
         pass
コード例 #11
0
 def run(self):
     Worker(channel_backend=self.channel_backend).run()
コード例 #12
0
ファイル: runserver.py プロジェクト: fcurella/channels
 def run(self):
     self.logger.debug("Worker thread running")
     worker = Worker(channel_layer=self.channel_layer, signal_handlers=False)
     worker.ready()
     worker.run()
     self.logger.debug("Worker thread exited")
コード例 #13
0
ファイル: runserver.py プロジェクト: pajusmar/channels
 def run(self):
     self.logger.debug("Worker thread running")
     worker = Worker(channel_layer=self.channel_layer)
     worker.run()
     self.logger.debug("Worker thread exited")
コード例 #14
0
 def run(self):
     worker = Worker(channel_layer=self.channel_layer,
                     signal_handlers=False)
     worker.ready()
     worker.run()
コード例 #15
0
 def run(self):
     self.logger.debug("Worker thread running")
     worker = Worker(channel_layer=self.channel_layer)
     worker.run()
     self.logger.debug("Worker thread exited")
コード例 #16
0
 def run(self):
     Worker(channel_layer=self.channel_layer).run()