Skip to main content

dispatcher/
dispatcher.rs

1// Copyright 2015-2025 Deyan Ginev. See the LICENSE
2// file at the top-level directory of this distribution.
3//
4// Licensed under the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>.
5// This file may not be copied, modified, or distributed
6// except according to those terms.
7use cortex::config::config;
8use cortex::dispatcher::manager::TaskManager;
9
10/// A dispatcher executable for `CorTeX` distributed processing with ZMQ
11fn main() {
12  // Leveled logging (RUST_LOG, default info); the hot-path narration is trace/debug — see
13  // `cortex::observability`.
14  cortex::observability::init_tracing();
15  // All operational parameters come from the runtime configuration
16  // (defaults → cortex.toml → CORTEX_ env); see `cortex::config`.
17  let cfg = config();
18  let manager = TaskManager {
19    source_port: cfg.dispatcher.source_port,
20    result_port: cfg.dispatcher.result_port,
21    // Note that queue_size must never be larger than postgresql's max_locks_per_transaction setting
22    //   (typically specified in /etc/postgresql/9.1/main/postgresql.conf or similar)
23    queue_size: cfg.dispatcher.queue_size,
24    message_size: cfg.dispatcher.message_size,
25    max_in_flight: cfg.dispatcher.max_in_flight,
26    backend_address: cfg.database.url.clone(),
27  };
28  // Graceful shutdown (O-1): on SIGTERM/SIGINT, stop leasing new work and drain the in-flight set +
29  // finalize batch before exiting, instead of the supervisor hard-killing in-flight tasks.
30  // Unexpected failures still fail-fast (panic → abort). Production-only — bounded test runs
31  // don't install this.
32  cortex::dispatcher::server::install_shutdown_handlers();
33  manager
34    .start(None)
35    .unwrap_or_else(|_| panic!("Failed to start TaskManager"));
36}