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
最满意答案
此操作迫使值为零的零。
[要么]
操作* 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.
相关问答
更多-
AND 0xFF是做什么的?(What does AND 0xFF do?)[2022-09-04]
与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位作为一 ...