在django中的异步任务处理程序之间切换,而不需要几秒钟。

django-swappable-tasks的Python项目详细描述


Django可交换任务

简介

Considering you have a django project running on different servers each with its own asynchronous tasks handler this project helps you have one way to process the tasks while converting to the respective handler in the background. Currently Google Cloud Tasks and Celery are supported.

代码示例

To set up you will need to add the following to your settings.py file DEFAULT_ASYNC_TASKS_HANDLER = env('DEFAULT_ASYNC_TASKS_HANDLER') This can either be CELERY or GOOGLE_CLOUD_TASKS.

如果您正在使用芹菜,请记住设置其他设置,如CELERY_BROKER_URLCELERY_RESULT_BACKENDCELERY_ACCEPT_CONTENTCELERY_TASK_SERIALIZERCELERY_RESULT_SERIALIZERCELERY_TIMEZONE

{{cd7>

将视图添加到项目中网址.py文件如下

from django.urls import path, include
urlpatterns = [
          ...
          path('tasks/', include('django_swappable_tasks.urls')),    
          ...    
]

假设你有如下任务

^{pr2}$

要异步处理任务,请执行以下操作

from django_swappable_tasks.utils import process_task_asynchronously
from my project.tasks import my_blocking_task
task_kwargs = {"name": "John Doe", "age" : 18}
process_task_asynchronously(my_blocking_task, "google_default_queue", task_args=[], task_kwargs= task_kwargs)

安装

To install the package do pip install django_swappable_tasks You can also directly install from The GitHub Repository

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java我应该卸载Eclipse,还是只在上面安装一个新版本?   Java For Loop i++在For Loop中做什么?   java防止击键从JTable级联到顶层   java在为GUI和游戏划分类时遇到问题:GUI未连接到游戏   客户端调用时java RMI服务器ClassNotFoundException   java如何在libgdx/box2d中为特定实体强制执行最大速度?   java在Selenium Webdriver中调用href值   java IndexOutOfBounds异常向ArrayList添加项   java修剪JsonNode中的所有字符串值   带填充列表的thymeleaf中的java空索引异常   JPanel中的java插入按钮   java应该在实现中添加Javadoc注释吗?   java JNI不满意的链接错误,尽管一切似乎都很好   java使用Youtube Api V3搜索Youtube视频