Crate psup_impl[][src]

Process supervisor with inter-process communication support using tokio.

Currently only supports Unix, later we plan to add support for Windows using named pipes.

Supervisor

Supervisor manages child processes sending socket information using the environment and then switching to Unix domain sockets for inter-process communication. Daemon processes are restarted if they die without being shutdown by the supervisor.

use psup::{Result, Task, SupervisorBuilder};

#[tokio::main]
async fn main() -> Result<()> {
   let worker_cmd = "worker-process";
   let supervisor = SupervisorBuilder::new(Box::new(|stream| {
           let (reader, mut writer) = stream.into_split();
           // Handle worker connections here
       }))
       .path(std::env::temp_dir().join("supervisor.sock"))
       .add_worker(Task::new(worker_cmd).daemon(true))
       .add_worker(Task::new(worker_cmd).daemon(true))
       .build();
   supervisor.run().await?;
   // Block the process here and do your work.
   Ok(())
}

Worker

Worker reads the socket information from the environment and then connects to the Unix socket.

use psup::{Result, worker};

#[tokio::main]
async fn main() -> Result<()> {
    // Read supervisor information from the environment 
    // and set up the IPC channel with the supervisor
    let worker = Worker::new(|stream| {
        let (reader, mut writer) = stream.into_split();
        // Start sending messages to the supervisor
    });
    worker.run().await?;
    // Block the process here and do your work.
    Ok(())
}

Structs

Supervisor

Supervisor manages long-running worker processes.

SupervisorBuilder

Build a supervisor.

Task

Defines a worker process command.

Worker

Worker process handler.

WorkerInfo

Message sent to worker handlers.

Enums

Error

Enumeration of errors.

Type Definitions

Result

Result type returned by the library.