Exemplo n.º 1
0
    def test_signal_with_pickle_mapped_argument(self):
        with self.settings(**self.dqsettings):
            import signalqueue
            signalqueue.autodiscover()
            from signalqueue.worker import queues

            #for queue in [q for q in queues.all() if q.queue_name is not 'celery']:

            for queue in queues.all():

                print "*** Testing queue: %s" % queue.queue_name
                #queue.clear()

                from signalqueue import SQ_DMV
                for regsig in SQ_DMV['signalqueue.tests']:
                    if regsig.name == "signal_with_object_argument_%s" % queue.queue_name:
                        signal_with_object_argument = regsig
                        break

                signal_with_object_argument.queue_name = str(queue.queue_name)
                signal_with_object_argument.connect(callback_no_exception)

                instances = TestModel.objects.all().iterator()
                testobj = TestObject('yo dogg')
                testexc = TestException()

                testobjects = [testobj, testexc]

                for testobject in testobjects:
                    sigstruct_send = signal_with_object_argument.send(
                        sender=instances.next(),
                        instance=instances.next(),
                        obj=testobject)

                    print "*** Queue %s: %s values, runmode is %s" % (
                        signal_with_object_argument.queue_name, queue.count(),
                        queue.runmode)
                    sigstruct_dequeue, result_list = queue.dequeue()

                    #from pprint import pformat
                    #print pformat(sigstruct_send, indent=4)
                    #print pformat(sigstruct_dequeue, indent=4)

                    self.assertEqual(sigstruct_send, sigstruct_dequeue)

                    # result_list is a list of tuples, each containing a reference
                    # to a callback function at [0] and that callback's return at [1]
                    # ... this is per what the Django signal send() implementation returns.
                    if result_list is not None:
                        resultobject = dict(result_list)[callback_no_exception]
                        print "*** resultobject (%s) = %s" % (
                            type(resultobject), resultobject)

                        #self.assertEqual(
                        #    resultobject, testobject)
                        #self.assertEqual(
                        #    type(resultobject), type(testobject))

                    else:
                        print "*** queue.dequeue() returned None"
Exemplo n.º 2
0
 def test_worker_status_timeout(self):
     dqsettings = dict(
         SQ_ADDITIONAL_SIGNALS=['signalqueue.tests'],
         SQ_RUNMODE='SQ_ASYNC_REQUEST')
     
     with self.settings(**dqsettings):
         import signalqueue
         signalqueue.autodiscover()
         from signalqueue.worker import queues
         queue = queues['db']
         
         oldcount = queue.count()
         from signalqueue.models import log_exceptions
         with log_exceptions(queue_name='db'):
             yodogg = queue.retrieve()
             queue.dequeue(queued_signal=yodogg)
         
         print "Sleeping for 0.5 seconds..."
         import time
         time.sleep(0.5)
         
         self.http_client.fetch(self.get_url('/status'), self.stop)
         response = self.wait(timeout=10)
         phrase = "%s enqueued signals" % queue.count()
         self.assertTrue(phrase in response.body)
         
         newcount = queue.count()
         self.assertTrue(int(oldcount) > int(newcount))
Exemplo n.º 3
0
    def test_worker_status_timeout(self):
        dqsettings = dict(SQ_ADDITIONAL_SIGNALS=['signalqueue.tests'],
                          SQ_RUNMODE='SQ_ASYNC_REQUEST')

        with self.settings(**dqsettings):
            import signalqueue
            signalqueue.autodiscover()
            from signalqueue.worker import queues
            queue = queues['db']

            oldcount = queue.count()

            yodogg = queue.retrieve()
            queue.dequeue(queued_signal=yodogg)

            print "Sleeping for 0.5 seconds..."
            import time
            time.sleep(0.5)

            cnt = queue.count() or 0
            self.http_client.fetch(self.get_url('/status'), self.stop)
            response = self.wait(timeout=10)
            phrase = "%s enqueued signals" % cnt
            #print "##########################################"
            #print phrase
            #print "##########################################"
            #print response.body
            #print "##########################################"
            #self.assertTrue(phrase in response.body)

            newcount = queue.count()
            self.assertTrue(int(oldcount) > int(newcount))
Exemplo n.º 4
0
 def setUp(self):
     from django.contrib.auth import models as auth_models
     self.testuser = '******'
     self.testpass = '******'
     
     try:
         self.user = auth_models.User.objects.get(username=self.testuser)
     except auth_models.User.DoesNotExist:
         assert auth_models.User.objects.create_superuser(self.testuser, '%s@%s.com' % (self.testuser, self.testuser), self.testpass)
         self.user = auth_models.User.objects.get(username=self.testuser)
     else:
         print 'Test user %s already exists.' % self.testuser
     
     from django.test.client import Client
     self.client = Client()
     
     import os
     self.testroot = os.path.dirname(os.path.abspath(__file__))
     
     self.dqsettings = dict(
         SQ_ADDITIONAL_SIGNALS=['signalqueue.tests'],
         SQ_RUNMODE='SQ_ASYNC_REQUEST')
     
     with self.settings(**self.dqsettings):
         import signalqueue
         signalqueue.autodiscover()
         from signalqueue.worker import queues
         self.queue = queues['db']
Exemplo n.º 5
0
 def setUp(self):
     import signalqueue, uuid
     with self.settings(SQ_ADDITIONAL_SIGNALS=['signalqueue.tests']):
         signalqueue.autodiscover()
     
     from signalqueue.worker import queues
     self.queue = queues['db']
     self.name = "Yo dogg: %s" % str(uuid.uuid4().hex)
Exemplo n.º 6
0
 def test_autodiscover(self):
     import signalqueue
     from signalqueue import signals
     
     signalqueue.autodiscover()
     
     for sig in [s for s in signals.__dict__.values() if isinstance(s, dispatcher.AsyncSignal)]:
         self.assertTrue(sig in signalqueue.SQ_DMV['signalqueue.signals'])
Exemplo n.º 7
0
 def setUp(self):
     self.dqsettings = dict(SQ_ADDITIONAL_SIGNALS=['signalqueue.tests'],
                            SQ_RUNMODE='SQ_ASYNC_REQUEST')
     with self.settings(**self.dqsettings):
         import signalqueue
         signalqueue.autodiscover()
         from signalqueue.worker import queues
         self.queue = queues['db']
Exemplo n.º 8
0
    def setUp(self):
        import signalqueue, uuid
        with self.settings(SQ_ADDITIONAL_SIGNALS=['signalqueue.tests']):
            signalqueue.autodiscover()

        from signalqueue.worker import queues
        self.queue = queues['db']
        self.name = "Yo dogg: %s" % str(uuid.uuid4().hex)
Exemplo n.º 9
0
 def handle(self, *args, **options):
     import signalqueue
     signalqueue.autodiscover()
     echo_banner()
     try:
         return self.purge_signal_queue(args, options)
     except ImproperlyConfigured, err:
         self.echo("*** ERROR in configuration: %s" % err)
         self.echo("*** Check the signalqueue-related options in your settings.py.")
Exemplo n.º 10
0
 def setUp(self):
     self.dqsettings = dict(
         SQ_ADDITIONAL_SIGNALS=['signalqueue.tests'],
         SQ_RUNMODE='SQ_ASYNC_REQUEST')
     with self.settings(**self.dqsettings):
         import signalqueue
         signalqueue.autodiscover()
         from signalqueue.worker import queues
         self.queue = queues['db']
Exemplo n.º 11
0
    def test_autodiscover(self):
        import signalqueue
        from signalqueue import signals

        signalqueue.autodiscover()

        for sig in [
                s for s in signals.__dict__.values()
                if isinstance(s, dispatcher.AsyncSignal)
        ]:
            self.assertTrue(sig in signalqueue.SQ_DMV['signalqueue.signals'])
Exemplo n.º 12
0
 def test_worker_dequeue_from_tornado_periodic_callback(self):
     from signalqueue import signals
     signals.test_signal.connect(callback)
     
     import signalqueue
     signalqueue.autodiscover()
     
     from django.core.management import call_command
     call_command('runqueueserver', '9920',
         queue_name='db', halt_when_exhausted=True, exit=False)
     
     from signalqueue.models import WorkerExceptionLog
     self.assertTrue(WorkerExceptionLog.objects.totalcount() > 10)
Exemplo n.º 13
0
    def test_additional_signals(self):
        #from signalqueue import signals

        with self.settings(SQ_ADDITIONAL_SIGNALS=['signalqueue.tests']):
            import signalqueue
            signalqueue.autodiscover()
            '''
            for k, v in signalqueue.SQ_DMV.items():
                print "%25s:" % k
                for val in v:
                    print "%25s %20s: %s" % ("", val.__class__.__name__, val.name) '''
            self.assertTrue(
                additional_signal in signalqueue.SQ_DMV['signalqueue.tests'])
Exemplo n.º 14
0
    def test_additional_signals(self):
        # from signalqueue import signals

        with self.settings(SQ_ADDITIONAL_SIGNALS=["signalqueue.tests"]):
            import signalqueue

            signalqueue.autodiscover()
            """
            for k, v in signalqueue.SQ_DMV.items():
                print "%25s:" % k
                for val in v:
                    print "%25s %20s: %s" % ("", val.__class__.__name__, val.name) """
            self.assertTrue(additional_signal in signalqueue.SQ_DMV["signalqueue.tests"])
Exemplo n.º 15
0
    def __init__(self, *args, **kwargs):
        super(PoolQueue, self).__init__()

        import signalqueue
        signalqueue.autodiscover()

        from django.conf import settings as django_settings
        from signalqueue.utils import logg
        from signalqueue.worker import backends
        from signalqueue import SQ_RUNMODES as runmodes

        self.active = kwargs.get('active', True)
        self.halt = kwargs.get('halt', False)
        self.logx = kwargs.get('log_exceptions', True)

        self.interval = 1
        self.queue_name = kwargs.get('queue_name', "default")

        self.runmode = runmodes['SQ_ASYNC_MGMT']
        self.queues = backends.ConnectionHandler(django_settings.SQ_QUEUES,
                                                 self.runmode)
        self.signalqueue = self.queues[self.queue_name]
        self.signalqueue.runmode = self.runmode
        self.logg = logg

        # use interval from the config if it exists
        interval = kwargs.get('interval', self.signalqueue.queue_interval)
        if interval is not None:
            self.interval = interval

        if self.interval > 0:

            if self.logx:
                if self.halt:
                    self.shark = PeriodicCallback(self.joe_flacco,
                                                  self.interval * 10)
                else:
                    self.shark = PeriodicCallback(self.ray_rice,
                                                  self.interval * 10)

            else:
                if self.halt:
                    self.shark = PeriodicCallback(self.cueball_scratch,
                                                  self.interval * 10)
                else:
                    self.shark = PeriodicCallback(self.cueball,
                                                  self.interval * 10)

        if self.active:
            self.shark.start()
Exemplo n.º 16
0
    def _test_worker_dequeue_from_tornado_periodic_callback(self):
        from signalqueue import signals
        signals.test_signal.connect(callback)

        import signalqueue
        signalqueue.autodiscover()

        from django.core.management import call_command
        call_command('runqueueserver',
                     '9920',
                     queue_name='db',
                     halt_when_exhausted=True,
                     exit=False)

        from signalqueue.models import WorkerExceptionLog
        self.assertTrue(WorkerExceptionLog.objects.totalcount() > 10)
Exemplo n.º 17
0
 def __init__(self, *args, **kwargs):
     super(PoolQueue, self).__init__()
     
     import signalqueue
     signalqueue.autodiscover()
     
     from django.conf import settings as django_settings
     from signalqueue.utils import logg
     from signalqueue.worker import backends
     from signalqueue import SQ_RUNMODES as runmodes
     
     self.active = kwargs.get('active', True)
     self.halt = kwargs.get('halt', False)
     self.logx = kwargs.get('log_exceptions', True)
     
     self.interval = 1
     self.queue_name = kwargs.get('queue_name', "default")
     
     self.runmode = runmodes['SQ_ASYNC_MGMT']
     self.queues = backends.ConnectionHandler(django_settings.SQ_QUEUES, self.runmode)
     self.signalqueue = self.queues[self.queue_name]
     self.signalqueue.runmode = self.runmode
     self.logg = logg
     
     # use interval from the config if it exists
     interval = kwargs.get('interval', self.signalqueue.queue_interval)
     if interval is not None:
         self.interval = interval
     
     if self.interval > 0:
         
         if self.logx:
             if self.halt:
                 self.shark = PeriodicCallback(self.joe_flacco, self.interval*10)
             else:
                 self.shark = PeriodicCallback(self.ray_rice, self.interval*10)
         
         else:
             if self.halt:
                 self.shark = PeriodicCallback(self.cueball_scratch, self.interval*10)
             else:
                 self.shark = PeriodicCallback(self.cueball, self.interval*10)
     
     if self.active:
         self.shark.start()
Exemplo n.º 18
0
 def test_signal_with_pickle_mapped_argument(self):
     import signalqueue
     signalqueue.autodiscover()
     from signalqueue.worker import queues
     
     for queue in queues.all():
         
         print "*** Testing queue: %s" % queue.queue_name
         queue.clear()
         
         from signalqueue import SQ_DMV
         for regsig in SQ_DMV['signalqueue.tests']:
             if regsig.name == "signal_with_object_argument_%s" % queue.queue_name:
                 signal_with_object_argument = regsig
                 break
         signal_with_object_argument.queue_name = str(queue.queue_name)
         signal_with_object_argument.connect(callback_no_exception)
         
         instance = TestModel.objects.all()[0]
         testobj = TestObject('yo dogg')
         testexc = TestException()
         
         testobjects = [testobj, testexc]
         
         for testobject in testobjects:
             sigstruct_send = signal_with_object_argument.send(sender=None, instance=instance, obj=testobject)
             print "*** Queue %s: %s values, runmode is %s" % (
                 signal_with_object_argument.queue_name, queue.count(), queue.runmode)
             sigstruct_dequeue, result_list = queue.dequeue()
             
             self.assertEqual(sigstruct_send, sigstruct_dequeue)
             
             # result_list is a list of tuples, each containing a reference
             # to a callback function at [0] and that callback's return at [1]
             # ... this is per what the Django signal send() implementation returns.
             if result_list is not None:
                 resultobject = dict(result_list)[callback_no_exception]
                 self.assertEqual(resultobject, testobject)
                 self.assertEqual(type(resultobject), type(testobject))
             else:
                 print "*** queue.dequeue() returned None"
Exemplo n.º 19
0
    def test_signal_with_pickle_mapped_argument(self):
        with self.settings(**self.dqsettings):
            import signalqueue

            signalqueue.autodiscover()
            from signalqueue.worker import queues

            # for queue in [q for q in queues.all() if q.queue_name is not 'celery']:

            for queue in queues.all():

                print "*** Testing queue: %s" % queue.queue_name
                # queue.clear()

                from signalqueue import SQ_DMV

                for regsig in SQ_DMV["signalqueue.tests"]:
                    if regsig.name == "signal_with_object_argument_%s" % queue.queue_name:
                        signal_with_object_argument = regsig
                        break

                signal_with_object_argument.queue_name = str(queue.queue_name)
                signal_with_object_argument.connect(callback_no_exception)

                instances = TestModel.objects.all().iterator()
                testobj = TestObject("yo dogg")
                testexc = TestException()

                testobjects = [testobj, testexc]

                for testobject in testobjects:
                    sigstruct_send = signal_with_object_argument.send(
                        sender=instances.next(), instance=instances.next(), obj=testobject
                    )

                    print "*** Queue %s: %s values, runmode is %s" % (
                        signal_with_object_argument.queue_name,
                        queue.count(),
                        queue.runmode,
                    )
                    sigstruct_dequeue, result_list = queue.dequeue()

                    # from pprint import pformat
                    # print pformat(sigstruct_send, indent=4)
                    # print pformat(sigstruct_dequeue, indent=4)

                    self.assertEqual(sigstruct_send, sigstruct_dequeue)

                    # result_list is a list of tuples, each containing a reference
                    # to a callback function at [0] and that callback's return at [1]
                    # ... this is per what the Django signal send() implementation returns.
                    if result_list is not None:
                        resultobject = dict(result_list)[callback_no_exception]
                        print "*** resultobject (%s) = %s" % (type(resultobject), resultobject)

                        # self.assertEqual(
                        #    resultobject, testobject)
                        # self.assertEqual(
                        #    type(resultobject), type(testobject))

                    else:
                        print "*** queue.dequeue() returned None"
Exemplo n.º 20
0
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

import signalqueue
signalqueue.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'yodogg.views.home', name='home'),
    # url(r'^yodogg/', include('yodogg.foo.urls')),
    
    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    
    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^signalqueue/', include('signalqueue.urls')),
    
)
Exemplo n.º 21
0
from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

import signalqueue
signalqueue.autodiscover()

urlpatterns = patterns(
    '',
    url(r'^admin/', include(admin.site.urls)),
)