Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def update_grid_cache(pkey):
with HUEY.lock_task('grid-cache-{}'.format(pkey)):
try:
d = Dataset.objects.get(pk=pkey)
d.update_grid_cache()
return 'Updated {} ({!s})'.format(d.name, d.pk)
except Dataset.DoesNotExist:
return 'Dataset did not exist, can not complete task'
except AttributeError:
return 'No update_grid_cache method on this dataset'
def update_layers(pkey):
with HUEY.lock_task('process-{}'.format(pkey)):
try:
d = Dataset.objects.get(pk=pkey)
d.update_layers()
return 'Processed {} ({!s})'.format(d.name, d.pk)
except Dataset.DoesNotExist:
return 'Dataset did not exist, can not complete task'
except AttributeError:
return 'No update_layers method on this dataset'
def load_tasks_async():
with HUEY.lock_task('import-lock'):
load_tasks(GitRepository(
settings.REPOSITORY_ROOT,
url=config.GITLOAD_URL,
branch=config.GITLOAD_BRANCH
))
configure_settings()
django.setup()
application = get_default_application()
# 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
import redis.exceptions
try:
HUEY.flush()
except redis.exceptions.ConnectionError:
# maybe Redis is not running
pass
if instrumented:
return
instrumented = True
# Avoid importing if not installed
if "huey.contrib.djhuey" not in settings.INSTALLED_APPS: # pragma: no cover
return
try:
from huey.contrib.djhuey import HUEY
except ImportError: # pragma: no cover
return
from scout_apm.huey import attach_scout_handlers
attach_scout_handlers(HUEY)
logger.debug("Instrumented huey.contrib.djhuey")
def handle(self, *args, **options):
# 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.
# this code is also in asgi.py. it should be in both places,
# to ensure the database is flushed in all circumstances.
from huey.contrib.djhuey import HUEY
HUEY.flush()
# need to set USE_REDIS = True, because it uses the test client
# to submit pages, and if the next page has a timeout as well,
# its timeout task should be queued.
import otree.common
otree.common.USE_REDIS = True
super().handle(*args, **options)
def get_redis_conn():
'''reuse Huey Redis connection'''
return HUEY.storage.conn
def get_redis_conn():
'''reuse Huey Redis connection'''
return HUEY.storage.conn