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

getdozer / dozer / 6034126612

31 Aug 2023 07:03AM UTC coverage: 77.119%. First build
6034126612

Pull #1945

github

Jesse-Bakker
Write dozer.lock
Pull Request #1945: Write dozer.lock

86 of 86 new or added lines in 9 files covered. (100.0%)

49169 of 63757 relevant lines covered (77.12%)

69984.15 hits per line

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

82.64
/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_tracing::LabelsAndProgress;
8
use dozer_types::models::api_endpoint::ApiEndpoint;
9
use dozer_types::models::flags::Flags;
10
use dozer_types::parking_lot::Mutex;
11
use tokio::runtime::Runtime;
12

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

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

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

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

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

25
use super::Contract;
26

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

37
impl<'a> Executor<'a> {
38
    // TODO: Refactor this to not require both `contract` and all of
×
39
    // connections, sources and sql
×
40
    #[allow(clippy::too_many_arguments)]
×
41
    pub async fn new(
30✔
42
        home_dir: &'a HomeDir,
30✔
43
        contract: &Contract,
30✔
44
        connections: &'a [Connection],
30✔
45
        sources: &'a [Source],
30✔
46
        sql: Option<&'a str>,
30✔
47
        api_endpoints: &'a [ApiEndpoint],
30✔
48
        checkpoint_factory_options: CheckpointFactoryOptions,
30✔
49
        labels: LabelsAndProgress,
30✔
50
    ) -> Result<Executor<'a>, OrchestrationError> {
30✔
51
        // Find the build path.
×
52
        let build_path = home_dir
30✔
53
            .find_latest_build_path()
30✔
54
            .map_err(|(path, error)| OrchestrationError::FileSystem(path.into(), error))?
30✔
55
            .ok_or(OrchestrationError::NoBuildFound)?;
30✔
56

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

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

×
75
        Ok(Executor {
30✔
76
            connections,
30✔
77
            sources,
30✔
78
            sql,
30✔
79
            checkpoint_factory: Arc::new(checkpoint_factory),
30✔
80
            endpoint_and_logs,
30✔
81
            labels,
30✔
82
        })
30✔
83
    }
30✔
84

×
85
    pub fn endpoint_and_logs(&self) -> &[(ApiEndpoint, LogEndpoint)] {
30✔
86
        &self.endpoint_and_logs
30✔
87
    }
30✔
88

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

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

×
111
        Ok(exec)
30✔
112
    }
30✔
113
}
×
114

×
115
pub fn run_dag_executor(
30✔
116
    dag_executor: DagExecutor,
30✔
117
    running: Arc<AtomicBool>,
30✔
118
    labels: LabelsAndProgress,
30✔
119
) -> Result<(), OrchestrationError> {
30✔
120
    let join_handle = dag_executor.start(running, labels)?;
30✔
121
    join_handle
30✔
122
        .join()
30✔
123
        .map_err(OrchestrationError::ExecutionError)
30✔
124
}
30✔
125

×
126
async fn create_log_endpoint(
30✔
127
    contract: &Contract,
30✔
128
    build_path: &BuildPath,
30✔
129
    endpoint_name: &str,
30✔
130
    checkpoint_factory: &CheckpointFactory,
30✔
131
) -> Result<LogEndpoint, OrchestrationError> {
30✔
132
    let endpoint_path = build_path.get_endpoint_path(endpoint_name);
30✔
133

×
134
    let schema = contract
30✔
135
        .endpoints
30✔
136
        .get(endpoint_name)
30✔
137
        .ok_or_else(|| BuildError::MissingEndpoint(endpoint_name.to_owned()))?;
30✔
138
    let schema_string =
30✔
139
        dozer_types::serde_json::to_string(schema).map_err(BuildError::SerdeJson)?;
30✔
140

×
141
    let descriptor_bytes = tokio::fs::read(&build_path.descriptor_path)
30✔
142
        .await
30✔
143
        .map_err(|e| {
30✔
144
            OrchestrationError::FileSystem(build_path.descriptor_path.clone().into(), e)
×
145
        })?;
30✔
146

×
147
    let log_prefix = AsRef::<Utf8Path>::as_ref(checkpoint_factory.prefix())
30✔
148
        .join(&endpoint_path.log_dir_relative_to_data_dir);
30✔
149
    let log = Log::new(checkpoint_factory.storage(), log_prefix.into(), false).await?;
60✔
150
    let log = Arc::new(Mutex::new(log));
30✔
151

30✔
152
    Ok(LogEndpoint {
30✔
153
        build_id: build_path.id.clone(),
30✔
154
        schema_string,
30✔
155
        descriptor_bytes,
30✔
156
        log,
30✔
157
    })
30✔
158
}
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

© 2025 Coveralls, Inc