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

getdozer / dozer / 6014473913

29 Aug 2023 02:45PM UTC coverage: 76.356% (-0.007%) from 76.363%
6014473913

push

github

web-flow
Add version to config and contract (#1938)

46 of 46 new or added lines in 11 files covered. (100.0%)

49075 of 64271 relevant lines covered (76.36%)

48221.44 hits per line

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

83.62
/dozer-cli/src/simple/executor.rs
1
use dozer_api::grpc::internal::internal_pipeline_server::LogEndpoint;
2
use dozer_cache::dozer_log::camino::Utf8Path;
3
use dozer_cache::dozer_log::home_dir::{BuildPath, HomeDir};
4
use dozer_cache::dozer_log::replication::Log;
5
use dozer_core::checkpoint::{CheckpointFactory, CheckpointFactoryOptions};
6
use dozer_core::processor_record::ProcessorRecordStore;
7
use dozer_types::models::api_endpoint::ApiEndpoint;
8
use dozer_types::models::flags::Flags;
9
use dozer_types::parking_lot::Mutex;
10
use tokio::runtime::Runtime;
11

12
use std::sync::{atomic::AtomicBool, Arc};
13

14
use dozer_types::models::source::Source;
15

16
use crate::pipeline::PipelineBuilder;
17
use crate::shutdown::ShutdownReceiver;
18
use dozer_core::executor::{DagExecutor, ExecutorOptions};
19

20
use dozer_types::indicatif::MultiProgress;
21

22
use dozer_types::models::connection::Connection;
23

24
use crate::errors::{BuildError, OrchestrationError};
25

26
use super::Contract;
27

28
pub struct Executor<'a> {
29
    connections: &'a [Connection],
30
    sources: &'a [Source],
31
    sql: Option<&'a str>,
32
    checkpoint_factory: Arc<CheckpointFactory>,
33
    /// `ApiEndpoint` and its log.
34
    endpoint_and_logs: Vec<(ApiEndpoint, LogEndpoint)>,
35
    multi_pb: MultiProgress,
36
}
37

×
38
impl<'a> Executor<'a> {
×
39
    pub async fn new(
30✔
40
        home_dir: &'a HomeDir,
30✔
41
        connections: &'a [Connection],
30✔
42
        sources: &'a [Source],
30✔
43
        sql: Option<&'a str>,
30✔
44
        api_endpoints: &'a [ApiEndpoint],
30✔
45
        checkpoint_factory_options: CheckpointFactoryOptions,
30✔
46
        multi_pb: MultiProgress,
30✔
47
    ) -> Result<Executor<'a>, OrchestrationError> {
30✔
48
        // Find the build path.
×
49
        let build_path = home_dir
30✔
50
            .find_latest_build_path()
30✔
51
            .map_err(|(path, error)| OrchestrationError::FileSystem(path.into(), error))?
30✔
52
            .ok_or(OrchestrationError::NoBuildFound)?;
30✔
53

×
54
        // Load pipeline checkpoint.
×
55
        let record_store = ProcessorRecordStore::new()?;
30✔
56
        let checkpoint_factory = CheckpointFactory::new(
30✔
57
            Arc::new(record_store),
30✔
58
            build_path.data_dir.to_string(),
30✔
59
            checkpoint_factory_options,
30✔
60
        )
30✔
61
        .await?
30✔
62
        .0;
×
63

×
64
        let mut endpoint_and_logs = vec![];
30✔
65
        for endpoint in api_endpoints {
60✔
66
            let log_endpoint =
30✔
67
                create_log_endpoint(&build_path, &endpoint.name, &checkpoint_factory).await?;
90✔
68
            endpoint_and_logs.push((endpoint.clone(), log_endpoint));
30✔
69
        }
×
70

×
71
        Ok(Executor {
30✔
72
            connections,
30✔
73
            sources,
30✔
74
            sql,
30✔
75
            checkpoint_factory: Arc::new(checkpoint_factory),
30✔
76
            endpoint_and_logs,
30✔
77
            multi_pb,
30✔
78
        })
30✔
79
    }
30✔
80

×
81
    pub fn endpoint_and_logs(&self) -> &[(ApiEndpoint, LogEndpoint)] {
30✔
82
        &self.endpoint_and_logs
30✔
83
    }
30✔
84

×
85
    pub async fn create_dag_executor(
30✔
86
        &self,
30✔
87
        runtime: &Arc<Runtime>,
30✔
88
        executor_options: ExecutorOptions,
30✔
89
        shutdown: ShutdownReceiver,
30✔
90
        flags: Flags,
30✔
91
    ) -> Result<DagExecutor, OrchestrationError> {
30✔
92
        let builder = PipelineBuilder::new(
30✔
93
            self.connections,
30✔
94
            self.sources,
30✔
95
            self.sql,
30✔
96
            self.endpoint_and_logs
30✔
97
                .iter()
30✔
98
                .map(|(endpoint, log)| (endpoint.clone(), Some(log.log.clone())))
30✔
99
                .collect(),
30✔
100
            self.multi_pb.clone(),
30✔
101
            flags,
30✔
102
        );
30✔
103

×
104
        let dag = builder.build(runtime, shutdown).await?;
60✔
105
        let exec = DagExecutor::new(dag, self.checkpoint_factory.clone(), executor_options)?;
30✔
106

×
107
        Ok(exec)
30✔
108
    }
30✔
109
}
×
110

×
111
pub fn run_dag_executor(
30✔
112
    dag_executor: DagExecutor,
30✔
113
    running: Arc<AtomicBool>,
30✔
114
) -> Result<(), OrchestrationError> {
30✔
115
    let join_handle = dag_executor.start(running)?;
30✔
116
    join_handle
30✔
117
        .join()
30✔
118
        .map_err(OrchestrationError::ExecutionError)
30✔
119
}
30✔
120

×
121
async fn create_log_endpoint(
30✔
122
    build_path: &BuildPath,
30✔
123
    endpoint_name: &str,
30✔
124
    checkpoint_factory: &CheckpointFactory,
30✔
125
) -> Result<LogEndpoint, OrchestrationError> {
30✔
126
    let endpoint_path = build_path.get_endpoint_path(endpoint_name);
30✔
127

×
128
    let contract = Contract::deserialize(build_path)?;
30✔
129
    let schema = contract
30✔
130
        .endpoints
30✔
131
        .get(endpoint_name)
30✔
132
        .ok_or_else(|| BuildError::MissingEndpoint(endpoint_name.to_owned()))?;
30✔
133
    let schema_string =
30✔
134
        dozer_types::serde_json::to_string(schema).map_err(BuildError::SerdeJson)?;
30✔
135

136
    let descriptor_bytes = tokio::fs::read(&build_path.descriptor_path)
30✔
137
        .await
30✔
138
        .map_err(|e| {
30✔
139
            OrchestrationError::FileSystem(build_path.descriptor_path.clone().into(), e)
×
140
        })?;
30✔
141

×
142
    let log_prefix = AsRef::<Utf8Path>::as_ref(checkpoint_factory.prefix())
30✔
143
        .join(&endpoint_path.log_dir_relative_to_data_dir);
30✔
144
    let log = Log::new(checkpoint_factory.storage(), log_prefix.into(), false).await?;
60✔
145
    let log = Arc::new(Mutex::new(log));
30✔
146

30✔
147
    Ok(LogEndpoint {
30✔
148
        build_id: build_path.id.clone(),
30✔
149
        schema_string,
30✔
150
        descriptor_bytes,
30✔
151
        log,
30✔
152
    })
30✔
153
}
30✔
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

© 2026 Coveralls, Inc