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

getdozer / dozer / 4829268814

pending completion
4829268814

Pull #1516

github

GitHub
Merge 845b68ec1 into f2ab0e6ce
Pull Request #1516: Prepare v0.1.19

35090 of 44737 relevant lines covered (78.44%)

11496.87 hits per line

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

0.91
/dozer-orchestrator/src/main.rs
1
use clap::Parser;
1✔
2
#[cfg(feature = "cloud")]
3
use dozer_orchestrator::cli::cloud::CloudCommands;
4
use dozer_orchestrator::cli::generate_config_repl;
5
use dozer_orchestrator::cli::types::{ApiCommands, AppCommands, Cli, Commands, ConnectorCommands};
6
use dozer_orchestrator::cli::{init_dozer, list_sources, LOGO};
7
use dozer_orchestrator::errors::{CliError, OrchestrationError};
8
use dozer_orchestrator::simple::SimpleOrchestrator;
9
#[cfg(feature = "cloud")]
10
use dozer_orchestrator::CloudOrchestrator;
11
use dozer_orchestrator::{set_ctrl_handler, set_panic_hook, shutdown, Orchestrator};
12
use dozer_types::models::telemetry::TelemetryConfig;
13
use dozer_types::tracing::{error, info};
14

15
use std::process;
16

×
17
fn main() {
×
18
    set_panic_hook();
×
19

×
20
    if let Err(e) = run() {
×
21
        error!("{}", e);
×
22
        process::exit(1);
×
23
    }
×
24
}
×
25

×
26
fn render_logo() {
×
27
    use std::println as info;
×
28
    const VERSION: &str = env!("CARGO_PKG_VERSION");
×
29

×
30
    info!("{LOGO}");
×
31
    info!("\nDozer Version: {VERSION}\n");
×
32
}
×
33

×
34
fn run() -> Result<(), OrchestrationError> {
×
35
    // Reloading trace layer seems impossible, so we are running Cli::parse in a closure
36
    // and then initializing it after reading the configuration. This is a hacky workaround, but it works.
37

×
38
    let cli = parse_and_generate()?;
×
39
    let mut dozer = init_orchestrator(&cli)?;
×
40

×
41
    let (shutdown_sender, shutdown_receiver) = shutdown::new(&dozer.runtime);
×
42
    set_ctrl_handler(shutdown_sender);
×
43

×
44
    // Now we have access to telemetry configuration
×
45
    let _telemetry = Telemetry::new(Some(&dozer.config.app_name), dozer.config.telemetry.clone());
×
46

×
47
    if let Some(cmd) = cli.cmd {
×
48
        // run individual servers
×
49
        match cmd {
×
50
            Commands::Api(api) => match api.command {
×
51
                ApiCommands::Run => {
×
52
                    render_logo();
×
53

×
54
                    dozer.run_api(shutdown_receiver)
×
55
                }
56
                ApiCommands::GenerateToken => {
×
57
                    let token = dozer.generate_token()?;
×
58
                    info!("token: {:?} ", token);
×
59
                    Ok(())
×
60
                }
61
            },
×
62
            Commands::App(apps) => match apps.command {
×
63
                AppCommands::Run => {
×
64
                    render_logo();
×
65

×
66
                    dozer.run_apps(shutdown_receiver, None)
×
67
                }
68
            },
×
69
            Commands::Connector(sources) => match sources.command {
×
70
                ConnectorCommands::Ls => list_sources(&cli.config_path),
×
71
            },
×
72
            Commands::Migrate(migrate) => {
×
73
                let force = migrate.force.is_some();
×
74

×
75
                dozer.migrate(force)
×
76
            }
×
77
            Commands::Clean => dozer.clean(),
×
78
            #[cfg(feature = "cloud")]
×
79
            Commands::Cloud(cloud) => match cloud.command.clone() {
×
80
                CloudCommands::Deploy => dozer.deploy(cloud, cli.config_path),
×
81
                CloudCommands::List => dozer.list(cloud),
82
                CloudCommands::Status(ref app) => dozer.status(cloud, app.app_id.clone()),
83
            },
×
84
            Commands::Init => {
85
                panic!("This should not happen as it is handled in parse_and_generate");
×
86
            }
87
        }
×
88
    } else {
×
89
        render_logo();
×
90

×
91
        dozer.run_all(shutdown_receiver)
×
92
    }
93
}
×
94

95
// Some commands dont need to initialize the orchestrator
×
96
// This function is used to run those commands
×
97
fn parse_and_generate() -> Result<Cli, OrchestrationError> {
×
98
    dozer_tracing::init_telemetry_closure(None, None, || -> Result<Cli, OrchestrationError> {
×
99
        let cli = Cli::parse();
×
100

×
101
        if let Some(Commands::Init) = cli.cmd {
×
102
            if let Err(e) = generate_config_repl() {
×
103
                error!("{}", e);
×
104
                Err(e)
×
105
            } else {
×
106
                // We need to exit here, otherwise the orchestrator will be initialized
107
                process::exit(0);
×
108
            }
×
109
        } else {
110
            Ok(cli)
×
111
        }
×
112
    })
×
113
}
×
114

×
115
fn init_orchestrator(cli: &Cli) -> Result<SimpleOrchestrator, CliError> {
×
116
    dozer_tracing::init_telemetry_closure(None, None, || -> Result<SimpleOrchestrator, CliError> {
×
117
        let res = init_dozer(cli.config_path.clone());
×
118

×
119
        match res {
×
120
            Ok(dozer) => Ok(dozer),
×
121
            Err(e) => {
×
122
                error!("{}", e);
×
123
                Err(e)
×
124
            }
×
125
        }
×
126
    })
×
127
}
×
128

129
struct Telemetry(dozer_tracing::WorkerGuard);
130

×
131
impl Telemetry {
×
132
    fn new(app_name: Option<&str>, config: Option<TelemetryConfig>) -> Self {
×
133
        Self(dozer_tracing::init_telemetry(app_name, config))
×
134
    }
×
135
}
136

×
137
impl Drop for Telemetry {
×
138
    fn drop(&mut self) {
×
139
        dozer_tracing::shutdown_telemetry();
×
140
    }
×
141
}
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