Expand description
Dependant processes.
Sometimes, a job or a service depends on something else to function properly. For example, to generate a GraphQL
schema, a server must be available. Or to start a server, DB must be up and running. To handle
such cases, there is a Dependency
trait.
Types that implement this trait are able to check if a dependency is available or to wait until the dependency becomes available. For example, if some job requires a TCP service for some job:
let service = TcpService::new(...);
service.wait().await.unwrap();
// here, the service is available...
job.run().await;
You can use provided TcpService
, HttpService
,
and FsEntry
. Or implement your own
(you would need async_trait
).
Process pool
It is also useful when you need to spawn a pool of long-running processes, and some of them depend on something else to start properly, such as an HTTP service being available or a file existing.
async fn run() -> steward::Result<()> {
server::build().run().await?;
client::build().run().await?;
ProcessPool::run_with_deps(vec![
PoolEntry::Process(server::watch()),
PoolEntry::ProcessWithDep {
process: client::watch(),
dependency: Box::new(HttpService {
tag: "server".to_string(),
addr: format!(
"http://{host}:{port}",
host = Config::SERVER_HOST(),
port = Config::SERVER_PORT()
)
.parse()
.unwrap(),
method: HttpMethod::GET,
timeout: Duration::from_secs(30),
}),
},
])
.await
}
Traits
- Dependency trait.
- Error returned from the
Dependency::wait
method must implement this trait.