def test_monitor(): assert Stat.get(0).sentinel == 0 c = Cluster() c.start() stats = monitor(run_once=True) c.stop() assert len(stats) > 0 found_c = False for stat in stats: if stat.cluster_id == c.pid: found_c = True assert stat.uptime() > 0 assert stat.empty_queues() is True break assert found_c is True
def test_cluster_initial(r): list_key = 'initial_test:q' r.delete(list_key) c = Cluster(list_key=list_key) assert c.sentinel is None assert c.is_idle assert c.start() > 0 assert c.sentinel.is_alive() is True assert c.is_running stat = c.stat assert stat.status == Conf.IDLE assert c.stop() is True assert c.sentinel.is_alive() is False assert c.has_stopped r.delete(list_key)
def test_cluster_initial(broker): broker.list_key = 'initial_test:q' broker.delete_queue() c = Cluster(broker=broker) assert c.sentinel is None assert c.stat.status == Conf.STOPPED assert c.start() > 0 assert c.sentinel.is_alive() is True assert c.is_running assert c.is_stopping is False assert c.is_starting is False sleep(0.5) stat = c.stat assert stat.status == Conf.IDLE assert c.stop() is True assert c.sentinel.is_alive() is False assert c.has_stopped assert c.stop() is False broker.delete_queue()
def handle(self, *args, **options): self.stdout.write(self.style.SUCCESS( 'Starting qcluster for queue {!r}'.format(options['queue']))) q = Cluster(get_broker(options['queue'])) q.start() if options.get('run_once', False): q.stop()
def test_monitor(monkeypatch): cluster_id = uuid.uuid4() assert Stat.get(pid=0, cluster_id=cluster_id).sentinel == 0 c = Cluster() c.start() stats = monitor(run_once=True) assert get_ids() is True c.stop() assert len(stats) > 0 found_c = False for stat in stats: if stat.cluster_id == c.cluster_id: found_c = True assert stat.uptime() > 0 assert stat.empty_queues() is True break assert found_c is True # test lock size monkeypatch.setattr(Conf, 'ORM', 'default') b = get_broker('monitor_test') b.enqueue('test') b.dequeue() assert b.lock_size() == 1 monitor(run_once=True, broker=b) b.delete_queue()
def test_monitor(monkeypatch): assert Stat.get(0).sentinel == 0 c = Cluster() c.start() stats = monitor(run_once=True) c.stop() assert len(stats) > 0 found_c = False for stat in stats: if stat.cluster_id == c.pid: found_c = True assert stat.uptime() > 0 assert stat.empty_queues() is True break assert found_c is True # test lock size monkeypatch.setattr(Conf, 'ORM', 'default') b = get_broker('monitor_test') b.enqueue('test') b.dequeue() assert b.lock_size() == 1 monitor(run_once=True, broker=b) b.delete_queue()
def test_monitor(): c = Cluster() c.start() stats = monitor(run_once=True) c.stop() assert len(stats) > 0 found_c = False for stat in stats: if stat.cluster_id == c.pid: found_c = True break assert found_c is True
def test_monitor(): assert Stat.get(0).sentinel == 0 c = Cluster() c.start() stats = monitor(run_once=True) c.stop() assert len(stats) > 0 found_c = False for stat in stats: if stat.cluster_id == c.pid: found_c = True assert stat.uptime() > 0 assert stat.empty_queues() is True break assert found_c is True # test lock size Conf.ORM = 'default' b = get_broker('monitor_test') b.enqueue('test') b.dequeue() assert b.lock_size() == 1 monitor(run_once=True, broker=b) b.delete_queue() Conf.ORM = None
def handle(self, *args, **options): q = Cluster() q.start() if options.get('run_once', False): q.stop()
import logging import signal from django.core.management.base import BaseCommand from django_q.cluster import Cluster from apps.bot.updater import Updater cluster = Cluster() updater = Updater() class Command(BaseCommand): help = 'Initiates the updater for the Telegram bot, as well as a cluster for Django-Q.' def add_arguments(self, parser): parser.add_argument('--bot-logging', type=int, default=30) def handle(self, *args, **options): logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=options['bot_logging']) cluster.start() self.bind_signals() self.register_handlers() self.stderr.write('Initiating the Updater...') updater.start_polling() self.stderr.write('Listening for updates...') @classmethod def register_handlers(cls): from apps.bot import handlers
def handle(self, *args, **options): q = Cluster(get_broker(options['worker_name'])) q.start()
def handle(self, *args, **options): q = Cluster() q.start()