首页 \ 问答 \ Django Celery任务排队(Django Celery tasks queue)

Django Celery任务排队(Django Celery tasks queue)

我有一个应用程序用django使用redis和celery进行一些异步任务。 我正在使用celery任务来执行一些存储过程。 该SP从5分钟到30分钟完全执行(取决于记录的数量)。 一切都很好。 但我需要能够多次执行任务。 但是现在当我运行任务而另一个用户也运行任务时,这两个任务同时执行。 我需要在队列中输入任务,并且仅在第一个任务完成时执行。 我的settings.py:

BROKER_URL = 'redis://localhost:6379/0'
CELERY_IMPORTS = ("pc.tasks", )
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend'

tasks.py

from __future__ import absolute_import
from celery.decorators import task
from celery import task, shared_task
from .models import Servicio, Proveedor, Lectura_FTP, Actualizar_Descarga
from .models import Lista_Archivos, Lista_Final, Buscar_Conci

@task
def carga_ftp():
    tabla = Proc_Carga()
    sp = tabla.carga()
    return None

@task
def conci(idprov,pfecha):
    conci = Buscar_Conci()
    spconc = conci.buscarcon(idprov,pfecha)

我以这种方式在视图中调用任务:

conci.delay(prov,DateV);

如何创建或设置一个队列列表,并且只有在之前的抽签结束时才会执行任务

提前致谢


I have an application made it with django using redis and celery for some asynchronous tasks. I am using the celery tasks to execute some stored procedures. This SP take from 5 mins to 30 mins to execute completely(depending in amount of records). Everything works great. But I need the be able to execute the tasks several times. but right now when I run task and another user run the task too, the two tasks are executed at the same time. I need the task enter in queue and only executed when the first task finish. My settings.py:

BROKER_URL = 'redis://localhost:6379/0'
CELERY_IMPORTS = ("pc.tasks", )
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend'

tasks.py

from __future__ import absolute_import
from celery.decorators import task
from celery import task, shared_task
from .models import Servicio, Proveedor, Lectura_FTP, Actualizar_Descarga
from .models import Lista_Archivos, Lista_Final, Buscar_Conci

@task
def carga_ftp():
    tabla = Proc_Carga()
    sp = tabla.carga()
    return None

@task
def conci(idprov,pfecha):
    conci = Buscar_Conci()
    spconc = conci.buscarcon(idprov,pfecha)

I call the tasks in my view in this way:

conci.delay(prov,DateV);

How can I create or setup a queue list of taks and everry tasks is executed only when the previous taks is finished

Thanks in advance


原文:https://stackoverflow.com/questions/29567488
更新时间:2022-08-29 07:08

最满意答案

此操作迫使值为零的零。
[要么]
操作* ch&0xff选择前8位,并且isspace验证值是否为空格char。


This operation is forcing zeros left of value.
[OR]
The operation *ch & 0xff select first 8 bits and isspace verify if value is space char.

相关问答

更多
  • 与0xFF整数只留下最低有效字节。 例如,要获得short s的第一个字节,可以写s & 0xFF 。 这通常被称为“掩蔽”。 如果byte1是单字节类型(如uint8_t )或者已经小于256(因此除了最低有效字节以外全部为零),则不需要屏蔽掉高位,因为它们已经为零。 当您使用签名类型时,请参阅 下面的tristopia PatrickSchlüter 的答案。 在进行按位操作时,我建议只使用无符号类型。 Anding an integer with 0xFF leaves only the least ...
  • 如果你不喜欢循环,请使用递归:) public static void test1() { class Chk { boolean c(int [] b, int val, int pos) { if (pos >= b.length) { return true; } if (b[pos] != val) { return false; ...
  • 它将result设置为(无符号)值,将8位value置于结果的最低8位。 这样的原因是必需的,即byte是Java中的一种签名类型。 如果你刚刚写道: int result = value; 那么result将以ff ff ff fe而不是00 00 00 fe 。 另一个微妙之处在于&被定义为只对int值1进行操作,所以发生的是: value被提升为int ( ff ff ff fe )。 0xff是一个int字面值( 00 00 00 ff )。 应用&来产生所需的result值。 (关键是转换为in ...
  • 使用array[0] = '\xff'; 将单个字符设置为十六进制数字。 或者array[0] = 0xff; 正如您在代码的第一部分中所做的那样,成功。 Use array[0] = '\xff'; to set a single char to a hex numerical. Or array[0] = 0xff; as you did in the first part of your code, successfully.
  • 变量addr是32位数据,而数组a中的每个元素都是8位。 代码的作用是将32位addr复制到数组a ,一次一个字节。 让我们来看看这一行: a[1] = (addr & 0xff00) >> 8; 然后一步一步做。 addr & 0xff00这会得到addr值的8到15位,操作后的结果是0x0000d300 。 >> 8这会将位移到右侧,所以0x0000d300变为0x000000d3 。 分配掩码的结果值并切换到a[1] 。 The variable addr is 32 bits of data, ...
  • 这个 #define s 0xFF 是一个十六进制整数常量的定义。 它具有int类型,其值为十进制表示法中的255。 这个 #define s '\xFF' 是由十六进制转义序列表示的整数字符常量的定义。 它也有类型int但它代表一个字符。 其数值计算方式不同。 根据C标准(第6.4.4.4节字符常量的第10页) ...如果整数字符常量包含单个字符或转义序列,则其值是当char类型的值为单个字符或转义序列值的对象转换为int类型时的结果。 看来,默认情况下,编译器将char类型的值视为signed ch ...
  • 此操作迫使值为零的零。 [要么] 操作* ch&0xff选择前8位,并且isspace验证值是否为空格char。 This operation is forcing zeros left of value. [OR] The operation *ch & 0xff select first 8 bits and isspace verify if value is space char.
  • 这是一个十六进制值,0x12345678,写成二进制,并用一些位置注释: |31 24|23 16|15 8|7 bit 0| +---------------+---------------+---------------+---------------+ |0 0 0 1 0 0 1 0|0 0 1 1 0 1 0 0|0 1 0 1 0 1 1 0|0 1 1 1 1 0 0 0| +---------------+---- ...
  • 为什么我们必须在移位操作后使用按位AND运算'&0xff'? Oxff是十六进制数,等于十进制255。 在您的情况下, & 0xff确保所有像素值范围在0到255之间(即正8位)。 例如,如果任何值大于255,则会将其截断为0-255 int value=257; int result = value & 0xff; // result will be 1 因此,它的作用就像余数运算符%的正值。 但是按位运算符&比余数运算符%更快。 int result = value % 256 ...
  • 正如@fuz建议的那样,这只是一个优化器的错误,它没有将foo & 0xff识别为在最初可能在原始函数中使用的上下文中的无操作。 在将项目的编译设置设置为“Release”后,我使用Borland C ++ Builder 6编译了以下代码片段: unsigned char foobar(int foo) { return (foo >> 16) & 0xff; } 这类似于您提供的非常密切的拆卸操作。 我们有一个32位的值,我们希望移位给定的位数,然后将其转换为字节值,基本上将原始值的16-23位作为一 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)