Skip to content

Commit

Permalink
graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jun 2, 2024
1 parent 1095d62 commit 44b19b4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
*docker*
23 changes: 23 additions & 0 deletions crates/common/src/graceful_shutdown.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use tokio::signal;

pub async fn shutdown_signal() {
let ctrl_c = async {
signal::ctrl_c().await.expect("failed to install Ctrl+C handler");
};

#[cfg(unix)]
let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("failed to install signal handler")
.recv()
.await;
};

#[cfg(not(unix))]
let terminate = std::future::pending::<()>();

tokio::select! {
_ = ctrl_c => {},
_ = terminate => {},
}
}
1 change: 1 addition & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod argvec;
pub mod graceful_shutdown;
pub mod job;
pub mod job_record;
pub mod job_trace;
Expand Down
4 changes: 4 additions & 0 deletions crates/delegator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use futures::{stream::FuturesUnordered, StreamExt};
use libp2p::gossipsub::Event;
use sharp_p2p_common::{
graceful_shutdown::shutdown_signal,
hash,
job::Job,
network::Network,
Expand Down Expand Up @@ -109,6 +110,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
send_topic_tx.send(serialized_job.into()).await?;
info!("Sent a new job: {}", hash!(&job));
},
_ = shutdown_signal() => {
break
}
else => break
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/executor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use futures::{stream::FuturesUnordered, StreamExt};
use libp2p::gossipsub::Event;
use sharp_p2p_common::{
graceful_shutdown::shutdown_signal,
hash,
job::Job,
job_record::JobRecord,
Expand Down Expand Up @@ -125,6 +126,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Some(Ok(job_witness)) = prover_scheduler.next() => {
info!("Calculated job_witness: {}", hash!(&job_witness));
},
_ = shutdown_signal() => {
break
}
else => break
};

Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ services:
dockerfile: delegator.dockerfile
depends_on:
- runtime
<<<<<<< HEAD
ports:
- "5678:5678/udp"
- "5679:5679/tcp"
=======
>>>>>>> f5e88e4 (graceful shutdown)
deploy:
resources:
limits:
Expand All @@ -41,9 +44,12 @@ services:
dockerfile: executor.dockerfile
depends_on:
- runtime
<<<<<<< HEAD
ports:
- "5698:5678/udp"
- "5699:5679/tcp"
=======
>>>>>>> f5e88e4 (graceful shutdown)
deploy:
resources:
limits:
Expand Down
12 changes: 12 additions & 0 deletions runtime.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,20 @@ COPY --from=stone-prover /bin/cpu_air_verifier /root/.local/bin/
WORKDIR /sharp-p2p

# Copy the current directory content into the container
<<<<<<< HEAD
COPY . .

# Install requirements
RUN cargo make python-requirements-install && \
cargo make python-bootloader-install
=======
COPY cairo/ cairo/
COPY requirements.txt requirements.txt

# Install requirements
RUN pip install -r requirements.txt && \
pip install cairo/

# Copy the current directory content into the container
COPY . .
>>>>>>> f5e88e4 (graceful shutdown)

0 comments on commit 44b19b4

Please sign in to comment.