• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 5831539996

pending completion
5831539996

Pull #1824

github

chubei
feat: Publish DAG to JSON
Pull Request #1824: feat: Publish Source contracts as JSON file

249 of 249 new or added lines in 14 files covered. (100.0%)

45567 of 61724 relevant lines covered (73.82%)

56287.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.66
/dozer-cli/src/simple/executor.rs
1
use dozer_api::grpc::internal::internal_pipeline_server::LogEndpoint;
2
use dozer_cache::dozer_log::home_dir::{BuildPath, HomeDir};
3
use dozer_cache::dozer_log::replication::{Log, LogOptions};
4
use dozer_types::models::api_endpoint::ApiEndpoint;
5
use tokio::runtime::Runtime;
6
use tokio::sync::Mutex;
7

8
use std::sync::atomic::AtomicBool;
9
use std::sync::Arc;
10

11
use dozer_types::models::source::Source;
12

13
use crate::pipeline::PipelineBuilder;
14
use dozer_core::executor::{DagExecutor, ExecutorOptions};
15

16
use dozer_types::indicatif::MultiProgress;
17

18
use dozer_types::models::connection::Connection;
19
use OrchestrationError::ExecutionError;
20

21
use crate::errors::OrchestrationError;
22

23
pub struct Executor<'a> {
24
    connections: &'a [Connection],
25
    sources: &'a [Source],
26
    sql: Option<&'a str>,
27
    /// `ApiEndpoint` and its log.
28
    endpoint_and_logs: Vec<(ApiEndpoint, LogEndpoint)>,
29
    multi_pb: MultiProgress,
30
}
31

32
impl<'a> Executor<'a> {
33
    pub async fn new(
6✔
34
        home_dir: &'a HomeDir,
6✔
35
        connections: &'a [Connection],
6✔
36
        sources: &'a [Source],
6✔
37
        sql: Option<&'a str>,
6✔
38
        api_endpoints: &'a [ApiEndpoint],
6✔
39
        log_options: LogOptions,
6✔
40
        multi_pb: MultiProgress,
6✔
41
    ) -> Result<Executor<'a>, OrchestrationError> {
6✔
42
        let build_path = home_dir
6✔
43
            .find_latest_build_path()
6✔
44
            .map_err(|(path, error)| OrchestrationError::FileSystem(path.into(), error))?
6✔
45
            .ok_or(OrchestrationError::NoBuildFound)?;
6✔
46
        let mut endpoint_and_logs = vec![];
6✔
47
        for endpoint in api_endpoints {
12✔
48
            let log_endpoint =
6✔
49
                create_log_endpoint(&build_path, &endpoint.name, log_options.clone()).await?;
18✔
50
            endpoint_and_logs.push((endpoint.clone(), log_endpoint));
6✔
51
        }
×
52

×
53
        Ok(Executor {
6✔
54
            connections,
6✔
55
            sources,
6✔
56
            sql,
6✔
57
            endpoint_and_logs,
6✔
58
            multi_pb,
6✔
59
        })
6✔
60
    }
6✔
61

×
62
    pub fn endpoint_and_logs(&self) -> &[(ApiEndpoint, LogEndpoint)] {
6✔
63
        &self.endpoint_and_logs
6✔
64
    }
6✔
65

×
66
    pub fn create_dag_executor(
6✔
67
        &self,
6✔
68
        runtime: Arc<Runtime>,
6✔
69
        executor_options: ExecutorOptions,
6✔
70
    ) -> Result<DagExecutor, OrchestrationError> {
6✔
71
        let builder = PipelineBuilder::new(
6✔
72
            self.connections,
6✔
73
            self.sources,
6✔
74
            self.sql,
6✔
75
            self.endpoint_and_logs
6✔
76
                .iter()
6✔
77
                .map(|(endpoint, log)| (endpoint.clone(), Some(log.log.clone())))
6✔
78
                .collect(),
6✔
79
            self.multi_pb.clone(),
6✔
80
        );
6✔
81

×
82
        let dag = builder.build(runtime)?;
6✔
83
        let exec = DagExecutor::new(dag, executor_options)?;
6✔
84

×
85
        Ok(exec)
6✔
86
    }
6✔
87
}
88

×
89
pub fn run_dag_executor(
6✔
90
    dag_executor: DagExecutor,
6✔
91
    running: Arc<AtomicBool>,
6✔
92
) -> Result<(), OrchestrationError> {
6✔
93
    let join_handle = dag_executor.start(running)?;
6✔
94
    join_handle.join().map_err(ExecutionError)
6✔
95
}
6✔
96

×
97
async fn create_log_endpoint(
6✔
98
    build_path: &BuildPath,
6✔
99
    endpoint_name: &str,
6✔
100
    log_options: LogOptions,
6✔
101
) -> Result<LogEndpoint, OrchestrationError> {
6✔
102
    let endpoint_path = build_path.get_endpoint_path(endpoint_name);
6✔
103

104
    let schema_string = tokio::fs::read_to_string(&endpoint_path.schema_path)
6✔
105
        .await
6✔
106
        .map_err(|e| OrchestrationError::FileSystem(endpoint_path.schema_path.into(), e))?;
6✔
107

108
    let descriptor_bytes = tokio::fs::read(&build_path.descriptor_path)
6✔
109
        .await
6✔
110
        .map_err(|e| {
6✔
111
            OrchestrationError::FileSystem(build_path.descriptor_path.clone().into(), e)
×
112
        })?;
6✔
113

114
    let log = Log::new(log_options, endpoint_path.log_dir.into_string(), false).await?;
6✔
115
    let log = Arc::new(Mutex::new(log));
6✔
116

6✔
117
    Ok(LogEndpoint {
6✔
118
        build_id: build_path.id.clone(),
6✔
119
        schema_string,
6✔
120
        descriptor_bytes,
6✔
121
        log,
6✔
122
    })
6✔
123
}
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc