-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy path16_graph_01.cc
More file actions
59 lines (49 loc) · 1.93 KB
/
16_graph_01.cc
File metadata and controls
59 lines (49 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <workflow/WFTaskFactory.h>
#include <workflow/WFGraphTask.h>
#include <workflow/HttpMessage.h>
#include <workflow/WFFacilities.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <stdlib.h>
using namespace protocol;
static WFFacilities::WaitGroup wait_group(1);
void http_callback(WFHttpTask *task)
{
HttpResponse *resp = task->get_resp();
const void *body;
size_t body_len;
resp->get_parsed_body(&body, &body_len);
fprintf(stderr, "[tid : %ld] body len : %zu\n", ::syscall(SYS_gettid), body_len);
}
int main()
{
WFHttpTask *task_01 = WFTaskFactory::create_http_task("http://www.baidu.com", 4, 2,
http_callback);
WFHttpTask *task_02 = WFTaskFactory::create_http_task("http://www.bing.com", 4, 2,
http_callback);
auto pwork1 = Workflow::create_parallel_work(nullptr);
pwork1->add_series(Workflow::create_series_work(task_01, nullptr));
pwork1->add_series(Workflow::create_series_work(task_02, nullptr));
WFHttpTask *task_03 = WFTaskFactory::create_http_task("http://www.zhihu.com", 4, 2,
http_callback);
WFHttpTask *task_04 = WFTaskFactory::create_http_task("http://www.tencent.com", 4, 2,
http_callback);
auto pwork2 = Workflow::create_parallel_work(nullptr);
pwork2->add_series(Workflow::create_series_work(task_03, nullptr));
pwork2->add_series(Workflow::create_series_work(task_04, nullptr));
WFGraphTask *graph = WFTaskFactory::create_graph_task([](WFGraphTask *) {
fprintf(stderr, "Graph task complete. Wakeup main process");
wait_group.done();
});
WFHttpTask *start_task = WFTaskFactory::create_http_task("http://www.sogou.com", 4, 2,
http_callback);
WFGraphNode& a = graph->create_graph_node(start_task);
WFGraphNode& b = graph->create_graph_node(pwork1);
WFGraphNode& c = graph->create_graph_node(pwork2);
/* Build the graph */
a-->b;
a-->c;
graph->start();
wait_group.wait();
return 0;
}