Exemplo n.º 1
0
def wrap_method_call(method_name: str, method_kwargs):
    if otree.common.USE_REDIS:
        redis_conn = get_redis_conn()
        response_key = redis_enqueue_method_call(redis_conn=redis_conn,
                                                 method_name=method_name,
                                                 method_kwargs=method_kwargs)
        return redis_get_method_retval(redis_conn=redis_conn,
                                       response_key=response_key)
    else:
        method = getattr(browser_bot_worker, method_name)
        return method(**method_kwargs)
Exemplo n.º 2
0
    def dispatch(self, request):
        get_redis_conn()  # why do we do this?
        session_info = BrowserBotsLauncherSessionCode.objects.first()
        if session_info:
            session = Session.objects.get(code=session_info.code)
            with get_redis_lock(name='start_links') or start_link_thread_lock:
                participant = (session.participant_set.filter(
                    visited=False).order_by('id').first())
                if not participant:
                    return HttpResponseNotFound(NO_PARTICIPANTS_LEFT_MSG)

                # 2014-10-17: needs to be here even if it's also set in
                # the next view to prevent race conditions
                participant.visited = True
                participant.save()

            return HttpResponseRedirect(participant._start_url())
        else:
            ctx = {
                'view': self,
                'title_text': 'Vent venligst',
                'body_text': 'Waiting for browser bots session to begin',
            }
            return render(request, "otree/WaitPage.html", ctx)
Exemplo n.º 3
0
 def handle(self, *args, **options):
     redis_conn = get_redis_conn()
     otree.bots.browser.redis_flush_bots(redis_conn)
     worker = otree.bots.browser.Worker(redis_conn)
     worker.redis_listen()
Exemplo n.º 4
0
import os
import django
from channels.routing import get_default_application
from . import configure_settings

os.environ['OTREE_USE_REDIS'] = '1'
configure_settings()
django.setup()
application = get_default_application()

from otree.common import release_any_stale_locks, get_redis_conn  # noqa

# clear any tasks in Huey DB, so they don't pile up over time,
# especially if you run the server without the timeoutworker to consume the
# tasks.
# ideally we would only schedule a task in Huey if timeoutworker is running,
# so that we don't pile up messages that never get consumed, but I don't know
# how and when to check if Huey is running, in a performant way.
# this code is also in timeoutworker.
from huey.contrib.djhuey import HUEY  # noqa

HUEY.flush()

from otree.bots.browser import redis_flush_bots  # noqa

redis_flush_bots(get_redis_conn())

# needs to happen after Django setup
release_any_stale_locks()