本文整理汇总了Python中django_rq.get_queue方法的典型用法代码示例。如果您正苦于以下问题:Python django_rq.get_queue方法的具体用法?Python django_rq.get_queue怎么用?Python django_rq.get_queue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_rq
的用法示例。
在下文中一共展示了django_rq.get_queue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_uploaded_file
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def handle_uploaded_file(request):
"""
:param request: Django Request
:type request: HttpRequest
"""
f = request.FILES['package']
temp_root = settings.TEMP_ROOT
if not os.path.exists(temp_root):
try:
mkdir_p(temp_root)
except OSError:
pass
package_temp_path = os.path.join(temp_root, str(uuid.uuid1()) + '.deb')
with open(package_temp_path, 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
os.chmod(package_temp_path, 0o755)
if settings.ENABLE_REDIS is True:
queue = django_rq.get_queue('high')
return queue.enqueue(handle_uploaded_package, package_temp_path)
else:
return handle_uploaded_package(package_temp_path)
示例2: __init__
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def __init__(self, config):
"""config is a dict that has an entry for queues"""
if "queues" not in config:
raise ConfigError(
f"'queues' not present in autoscaler config:\nFound: {config}"
)
self.queues = [django_rq.get_queue(name) for name in config["queues"]]
if "max_workers" not in config:
raise ConfigError(
f"'max_workers' not present in autoscaler config:\nFound: {config}"
)
self.max_workers = config["max_workers"]
if "worker_reserve" not in config:
raise ConfigError(
f"'worker_reserve' not present in autoscaler config:\nFound: {config}"
)
self.worker_reserve = config["worker_reserve"]
示例3: handle_uploaded_image
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def handle_uploaded_image(request, package_id, gallery_slug):
"""
:param package_id: str
:param gallery_slug: str
:param request: Django Request
:type request: HttpRequest
"""
i = request.FILES['image']
temp_root = settings.TEMP_ROOT
allow_ext = ['.png', '.jpg', '.gif']
ext = os.path.splitext(i.name)[1].lower()
if ext in allow_ext:
if not os.path.exists(temp_root):
mkdir_p(temp_root)
image_temp_path = os.path.join(temp_root, str(uuid.uuid1()) + ext)
with open(image_temp_path, 'wb+') as destination:
for chunk in i.chunks():
destination.write(chunk)
os.chmod(image_temp_path, 0o755)
content = {
'id': package_id,
'slug': gallery_slug,
'path': image_temp_path
}
if settings.ENABLE_REDIS is True:
queue = django_rq.get_queue('high')
return queue.enqueue(handle_uploaded_screenshot, content)
else:
return handle_uploaded_screenshot(content)
else:
result_dict = {
'success': False,
'exception': _('Upload failed, unsupported file extension.')
}
return result_dict
示例4: update_storage
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def update_storage(self):
"""
Update control fields and write to deb files
This method is executed async.
"""
control = self.get_control_dict()
path = self.storage.name
if settings.ENABLE_REDIS is True:
queue = django_rq.get_queue('high')
update_job = queue.enqueue(write_to_package_job, control, path, self.id)
return update_job
else:
write_to_package_job(control, path, self.id)
return None
示例5: batch_hash_update
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def batch_hash_update(self, request, queryset):
"""
:type queryset: QuerySet
"""
if settings.ENABLE_REDIS is True:
queue = django_rq.get_queue('high')
queue.enqueue(hash_update_job, queryset)
self.message_user(request, _("Hash updating job has been added to the \"high\" queue."))
else:
hash_update_job(queryset)
self.message_user(request, _("Hash updating job has been finished."))
示例6: job_link
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def job_link(self, obj):
if obj.job_id is None:
if obj.is_finished:
return mark_safe("<img src=\"/static/admin/img/icon-yes.svg\" alt=\"True\" /> %s" % _('Finished'))
else:
return mark_safe("<img src=\"/static/admin/img/icon-unknown.svg\" alt=\"Unknown\" /> %s" % _('Unknown'))
m_job = queues.get_queue('high').fetch_job(obj.job_id)
if m_job is None:
return _('No such job')
if m_job.is_failed:
status_str = mark_safe("<img src=\"/static/admin/img/icon-no.svg\" alt=\"False\" /> %s" % _('Failed'))
elif m_job.is_finished:
if obj.is_finished:
status_str = mark_safe("<img src=\"/static/admin/img/icon-yes.svg\" alt=\"True\" /> %s" % _('Finished'))
else:
status_str = mark_safe(
"<img src=\"/static/admin/img/icon-unknown.svg\" alt=\"Unknown\" /> %s" % _('Unknown'))
else:
status_str = mark_safe("<img src=\"/static/img/icon-loading.svg\" width=\"13\" alt=\"Loading\" "
"onload=\"setTimeout(function () { window.location.reload(); }, 2000);\" /> "
"%s" % _("Processing..."))
return mark_safe('<a href="%s" target="_blank">%s</a>' % (
reverse('rq_job_detail', kwargs={
'queue_index': 1,
'job_id': m_job.id
}),
status_str
))
示例7: test_makemessages_django_rq_single_run
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def test_makemessages_django_rq_single_run(self):
queue = get_queue('default')
queue.enqueue(tasks.makemessages_task)
get_worker().work(burst=True)
示例8: test_makemessages_django_tq_more_jobs
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def test_makemessages_django_tq_more_jobs(self):
queue = get_queue('default')
queue.enqueue(tasks.makemessages_task)
queue.enqueue(tasks.makemessages_task)
queue.enqueue(tasks.makemessages_task)
get_worker().work(burst=True)
示例9: __init__
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def __init__(self):
super().__init__()
self.queue = django_rq.get_queue('wagtail_localize_pontoon.sync')
示例10: start_build
# 需要导入模块: import django_rq [as 别名]
# 或者: from django_rq import get_queue [as 别名]
def start_build(build, lock_id=None):
queue = django_rq.get_queue(build.plan.queue)
result = queue.enqueue(
run_build, build.id, lock_id, job_timeout=build.plan.build_timeout
)
build.task_id_check = None
build.task_id_run = result.id
build.save()
autoscale()
return result