当我将任务路由到特定队列时,它可以工作:
task.apply_async(queue='beetroot')
Run Code Online (Sandbox Code Playgroud)
但如果我创建一个链:
chain = task | task
Run Code Online (Sandbox Code Playgroud)
然后我写
chain.apply_async(queue='beetroot')
Run Code Online (Sandbox Code Playgroud)
它似乎忽略了queue关键字并分配给默认的'celery'队列.
如果芹菜支持链中的路由会很好 - 所有任务在同一队列中按顺序执行.
如何在不使用重定向的情况下将整个模型从一个控制器传递到另一个控制器?
我知道它有效,但我不知道为什么以及如何.有什么机制?
// Parent constructor
function Parent(name){
this.name = name || "The name property is empty";
}
// Child constructor
function Child(name){
this.name = name;
}
// Originaly, the Child "inherit" everything from the Parent, also the name property, but in this case
// I shadowing that with the name property in the Child constructor.
Child.prototype = new Parent();
// I want to this: if I dont set a name, please inherit "The name property is empty" from the
// Parent …Run Code Online (Sandbox Code Playgroud) 我想要一个可以使用管道操作符从dplyr导出的函数.我没有使用magrittr.
df %>% my_function
Run Code Online (Sandbox Code Playgroud)
我如何获得df名称?如果我试试
my_function <- function(tbl){print(deparse(substitute(tbl)))}
Run Code Online (Sandbox Code Playgroud)
它返回
[1] "."
Run Code Online (Sandbox Code Playgroud)
虽然我想[1]"df"
有什么建议吗?
谢谢你在前进,
尼古拉
假设我有一个数组数组,我想返回数组中每个数组的第一个元素:
array = [[["028A","028B","028C","028D","028E"],
["028F","0290","0291","0292","0293"],
["0294","0295","0296","0297","0298"],
["0299","029A","029B","029C","029D"],
["029E","029F","02A0","02A1","02A2"]],
[["02A3","02A4"],
["02A5", "02A6"]];
Run Code Online (Sandbox Code Playgroud)
我知道我可以这样做:
var firsts = [];
_.each(array, function(item){
_.each(item, function(thisitem){
firsts.push(_.first(thisitem));
});
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我想用下划线的_.chain()方法做什么呢?只是学习下划线,到目前为止似乎非常有用.
例如...
if ( /* Condition */ ) {
if ( /* Condition */ ) {
if ( /* Condition */ ) {
// Superb!
} else {
// Error 3
}
} else {
// Error 2
}
} else {
// Error 1
}
Run Code Online (Sandbox Code Playgroud)
你知道怎么避免这个吗?谢谢!
这是JavaScript的大师的问题.我正在尝试使用JavaScript原型模型更优雅.这是我的实用程序代码(它提供了真实的原型链和使用instanceof运算符的正确工作):
function Class(conf) {
var init = conf.init || function () {};
delete conf.init;
var parent = conf.parent || function () {};
delete conf.parent;
var F = function () {};
F.prototype = parent.prototype;
var f = new F();
for (var fn in conf) f[fn] = conf[fn];
init.prototype = f;
return init;
};
Run Code Online (Sandbox Code Playgroud)
它允许我这样做:
var Class_1 = new Class({
init: function (msg) { // constructor
this.msg = msg;
},
method_1: function () {
alert(this.msg + ' in Class_1::method_1');
},
method_2: function …Run Code Online (Sandbox Code Playgroud) 我需要链接两个MapReduce作业.我使用JobControl将job2设置为job1的依赖.它工作,输出文件被创建!! 但它并没有停止!在shell中它保持这种状态:
12/09/11 19:06:24 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
12/09/11 19:06:25 INFO input.FileInputFormat: Total input paths to process : 1
12/09/11 19:06:25 INFO util.NativeCodeLoader: Loaded the native-hadoop library
12/09/11 19:06:25 WARN snappy.LoadSnappy: Snappy native library not loaded
12/09/11 19:07:00 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
12/09/11 19:07:00 INFO input.FileInputFormat: Total input paths to process : 1
Run Code Online (Sandbox Code Playgroud)
我怎么能阻止它?这是我的主要.
public static void main(String[] …Run Code Online (Sandbox Code Playgroud) 我的问题可能很基本,但我仍然无法在官方文档中找到解决方案.我在Django应用程序中定义了一个Celery链,执行一组依赖于eanch其他的任务:
chain( tasks.apply_fetching_decision.s(x, y),
tasks.retrieve_public_info.s(z, x, y),
tasks.public_adapter.s())()
Run Code Online (Sandbox Code Playgroud)
显然,第二个和第三个任务需要父项的输出,这就是我使用链的原因.
现在的问题是:如果第一个任务中的测试条件失败,我需要以编程方式撤销第二个和第三个任务.如何以干净的方式做到这一点?我知道我可以从我定义链的方法中撤销链的任务(参见这个问题和本文),但在第一个任务中,我没有后续任务的可见性,也没有链本身的可见性.
我目前的解决方案是根据前一个任务的结果跳过后续任务中的计算:
@shared_task
def retrieve_public_info(result, x, y):
if not result:
return []
...
@shared_task
def public_adapter(result, z, x, y):
for r in result:
...
Run Code Online (Sandbox Code Playgroud)
但这种"解决方法"有一些缺陷:
我没有玩太多将链的引用传递给任务,因为害怕搞乱事情.我也承认我还没有尝试过抛出异常的方法,因为我认为不进行链接的选择可能是一个功能性(因此非特殊)的情况......
谢谢你的帮助!
相当简单的场景,但我在Google上找不到任何相关内容,所以这里有:
class ContainerClass implements Parcelable {
List<ItemClass> _items;
(...)
public void writeToParcel( Parcel p, int args ) {
p.writeList( _items );
(...)
}
}
class ItemClass implements Parcelable {
ContainerClass _containerRef;
(...)
public void writeToParcel( Parcel p, int args ) {
p.writeParcelable( _containerRef );
(...)
}
}
Run Code Online (Sandbox Code Playgroud)
这将不可避免地循环并溢出堆栈.
我的问题:我应该如何处理我必须将上述类型的对象传递给新Activity的情况.
(对于CommonsWare)Parcelable实现确实似乎没有检查,并避免循环依赖.具有由上述名称替换的类名的Stacktrace:
08-12 10:17:45.233 5590-5590/com.package E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.StackOverflowError
at com.package.ContainerClass.writeToParcel(ContainerClass.java:139)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at com.package.ItemClass.writeToParcel(ItemClass.java:182)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at android.os.Parcel.writeValue(Parcel.java:1173)
at android.os.Parcel.writeList(Parcel.java:622)
at com.package.ContainerClass.writeToParcel(ContainerClass.java:144)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at com.package.ItemClass.writeToParcel(ItemClass.java:182)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at android.os.Parcel.writeValue(Parcel.java:1173) …Run Code Online (Sandbox Code Playgroud) chain ×10
javascript ×4
celery ×2
prototype ×2
android ×1
call ×1
chaining ×1
constructor ×1
controller ×1
django ×1
dplyr ×1
forward ×1
grails ×1
hadoop ×1
inheritance ×1
job-control ×1
loops ×1
mapreduce ×1
model ×1
parcelable ×1
pipe ×1
python ×1
r ×1
rabbitmq ×1
task ×1