workflow.cpp 1.7 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8
#include "common/inner_common.h"
#include "framework/workflow.h"
#include "framework/predictor_metric.h" // PredictorMetric

namespace baidu {
namespace paddle_serving {
namespace predictor {

W
wangguibao 已提交
9 10 11
int Workflow::init(const configure::Workflow& conf) {
    const std::string& name = conf.name();
    _type = conf.workflow_type();
W
wangguibao 已提交
12
    _name = name;
W
wangguibao 已提交
13
    if (_dag.init(conf, name) != 0) {
W
wangguibao 已提交
14 15 16 17 18 19 20 21 22
        LOG(ERROR) << "Failed initialize dag: " << _name;
        return -1;
    }
    return 0;
}

DagView* Workflow::fetch_dag_view(const std::string& service_name) {
    DagView* view = NULL;
    if (_type == "Sequence") {
W
wangguibao 已提交
23
        view = butil::get_object<DagView>();
W
wangguibao 已提交
24
    } else if (_type == "Parallel") {
W
wangguibao 已提交
25
        view = butil::get_object<ParallelDagView>();
W
wangguibao 已提交
26
    } else {
27
        LOG(ERROR) 
W
wangguibao 已提交
28 29 30 31
            << "Unknown dag type:" << _type << "!";
        return NULL;
    }
    if (view == NULL) {
32
        LOG(ERROR) << "create dag view from pool failed!";
W
wangguibao 已提交
33 34 35 36 37 38 39 40 41
        return NULL;
    }
    view->init(&_dag, service_name);
    return view;
}

void Workflow::return_dag_view(DagView* view) {
    view->deinit();
    if (_type == "Sequence") {
W
wangguibao 已提交
42
        butil::return_object<DagView>(view);
W
wangguibao 已提交
43
    } else if (_type == "Parallel") {
W
wangguibao 已提交
44
        butil::return_object<ParallelDagView>(
W
wangguibao 已提交
45 46
            dynamic_cast<ParallelDagView*>(view));
    } else {
47
        LOG(ERROR) 
W
wangguibao 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
            << "Unknown dag type:" << _type << "!";
        return ;
    }
}

int Workflow::reload() {
    // reload op's config here...

    return 0;
}

void Workflow::regist_metric(const std::string& service_name) {
    PredictorMetric::GetInstance()->regist_latency_metric(
            WORKFLOW_METRIC_PREFIX + service_name + NAME_DELIMITER + full_name());
    _dag.regist_metric(service_name);
}

} // predictor
} // paddle_serving
} // baidu