Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server端如何使用WFGraphNode #607

Closed
chanchann opened this issue Oct 20, 2021 · 3 comments
Closed

server端如何使用WFGraphNode #607

chanchann opened this issue Oct 20, 2021 · 3 comments

Comments

@chanchann
Copy link
Contributor

当我们服务器端有比较复杂的逻辑时,想用DAG构建业务逻辑

正确打开方式是怎样的呢

下面是错误代码

    WFHttpServer server([](WFHttpTask *server_task) { 
        WFGraphTask *graph = WFTaskFactory::create_graph_task(nullptr);
        WFGraphNode& server_node = graph->create_graph_node(server_task);
        
        auto http_task_01 = WFTaskFactory::create_http_task("www.baidu.com", 4, 2, http_callback);
        auto http_task_02 = WFTaskFactory::create_http_task("www.bing.com", 4, 2, http_callback);
        WFGraphNode& http_node_01 = graph->create_graph_node(http_task_01);
        WFGraphNode& http_node_02 = graph->create_graph_node(http_task_02);
        server_node-->http_node_01;
        server_node-->http_node_02;
    });
@Barenboim
Copy link
Contributor

Barenboim commented Oct 20, 2021

你这个想法很有意思!但是这个代码不可行。不可以用server task来产生一个graph node。
正确的方式是:

    WFHttpServer server([](WFHttpTask *server_task) { 
        WFGraphTask *graph = WFTaskFactory::create_graph_task(nullptr);

        auto http_task_01 = WFTaskFactory::create_http_task("www.baidu.com", 4, 2, http_callback);
        auto http_task_02 = WFTaskFactory::create_http_task("www.bing.com", 4, 2, http_callback);

        WFGraphNode& http_node_01 = graph->create_graph_node(http_task_01);
        WFGraphNode& http_node_02 = graph->create_graph_node(http_task_02);

        http_node_01-->http_node_02;

        series_of(server_task)->push_back(graph);
    });

graph是一种任务,可以添加到server task所在的series。以上代码先抓取baidu.com,再抓取bing.com,之后回复请求。如果去掉'http_node_01-->http_node_02;'这句,则相当于图里没有任何边,两个抓取并行执行,都结束之后回复请求。

@chanchann
Copy link
Contributor Author

。◕◡◕。)ノ 感谢指导

@chanchann
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants