Coder Social home page Coder Social logo

Comments (8)

Barenboim avatar Barenboim commented on August 16, 2024 1

一个简单例子,需要更新到最新代码:

#include <iostream>
#include "workflow/WFFacilities.h"
#include "workflow/WFTaskFactory.h"

WFFacilities::WaitGroup wait_group(1);

SubTask *f(WFDynamicTask *)
{
    std::string url;
    std::cin >> url;
    return WFTaskFactory::create_http_task(url, 3, 0, [](WFHttpTask *task) {
        const void *body;
        size_t size;

        if (task->get_resp()->get_parsed_body(&body, &size))
            std::cout << (const char *)body;

        wait_group.done();
    });
}

int main()
{
    WFDynamicTask *t = WFTaskFactory::create_dynamic_task(f);
    t->start();
    wait_group.wait();
    return 0;
}

from workflow.

Barenboim avatar Barenboim commented on August 16, 2024 1

我看了看taskflow里的讨论,其实在我们的系统里现在这个问题同样是一个开放性问题,目前在解决方案上我们的选择比taskflow还是要多一些的,起码有个series context可以用来作为公共上下文。
其实更难解决的问题是在DAG这个场景下。因为DAG里每个任务都可能有多个前驱节点,每个节点会产生不同的输出。目前我们有一个模块是可以解决这个问题的,但因为使用便利性的问题,还没有正式标准化。
另外,如果对DAG有使用需求,我们提供了WFGraphTask。这个模块的实现有点参考taskflow,也是用了precede函数。但同样的,没有为节点间传递数据的问题提供统一方案,用户需要自己解决。在DAG里,WFDynamicTask就显得尤为重要了。

from workflow.

Barenboim avatar Barenboim commented on August 16, 2024

同一个series吗?series->set_context(),get_context()。

from workflow.

pi1ot avatar pi1ot commented on August 16, 2024

同一个series吗?series->set_context(),get_context()。

看起来是类似全剧变量或者参数服务器这样的解决方案,有没有可能使用更自然的函数返回值和函数参数这样的组合形式?

from workflow.

Barenboim avatar Barenboim commented on August 16, 2024

不好弄,主要是task的形态比较自由。你可能是想一上来就把task都创建好,不用写callback? 你可以试试WFDynamicTask,这种task通过一个函数在它实际启动的时候再生成具体的task。也许能用上。

from workflow.

pi1ot avatar pi1ot commented on August 16, 2024

不好弄,主要是task的形态比较自由。你可能是想一上来就把task都创建好,不用写callback? 你可以试试WFDynamicTask,这种task通过一个函数在它实际启动的时候再生成具体的task。也许能用上。

多谢,方便给个example或者demo代码的url吗?

from workflow.

Barenboim avatar Barenboim commented on August 16, 2024

WFDynamicTask *WFTaskFactory::create_dynamic_task(std::function<SubTask *()> func);
func返回一个任意类型的task,并且作为下一个task被启动。不过我突然觉得接口这样更好:
WFDynamicTask *WFTaskFactory::create_dynamic_task(std::function<SubTask *(WFDynamicTask *)> func);
下一个版本改一下。
不一定能直接解决你的问题,但是可以把一切任务变成动态创建,避免callback。要做成你说的形式,可能还需要再进行封装。

from workflow.

pi1ot avatar pi1ot commented on August 16, 2024

WFDynamicTask *WFTaskFactory::create_dynamic_task(std::function<SubTask *()> func);
func返回一个任意类型的task,并且作为下一个task被启动。不过我突然觉得接口这样跟好:
WFDynamicTask *WFTaskFactory::create_dynamic_task(std::function<SubTask *(WFDynamicTask *)> func);
下一个版本改一下。
不一定能直接解决你的问题,但是可以把一切任务变成动态创建,避免callback。要做成你说的形式,可能还需要再进行封装。

不好意思,可能误会了,我的本意并不是不写回调,是在workflow的基础上怎么实现dataflow。
比如一个workflow:task1 -> task2 -> task3
怎么让task1返回或者更新的data1能传递给task2,进而让task2的输出能传递给task3,参见这个讨论:
taskflow/taskflow#41

from workflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.