File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -165,9 +165,19 @@ async fn main() {
165165 log:: info!( "NATS worker loop ended" ) ;
166166 } ) ;
167167
168+ #[ cfg( unix) ]
169+ let sigterm = async {
170+ use tokio:: signal:: unix:: { SignalKind , signal} ;
171+
172+ let mut term = signal ( SignalKind :: terminate ( ) ) . expect ( "failed to install SIGTERM handler" ) ;
173+ term. recv ( ) . await ;
174+ } ;
175+
176+ #[ cfg( not( unix) ) ]
177+ let sigterm = std:: future:: pending :: < ( ) > ( ) ;
178+
168179 match health_task {
169180 Some ( mut health_task) => {
170- // both are mutable JoinHandle<()> so we can borrow them in select!
171181 tokio:: select! {
172182 _ = & mut worker_task => {
173183 log:: warn!( "NATS worker task finished, shutting down" ) ;
@@ -182,6 +192,11 @@ async fn main() {
182192 worker_task. abort( ) ;
183193 health_task. abort( ) ;
184194 }
195+ _ = sigterm => {
196+ log:: info!( "SIGTERM received, shutting down" ) ;
197+ worker_task. abort( ) ;
198+ health_task. abort( ) ;
199+ }
185200 }
186201 }
187202 None => {
@@ -193,6 +208,10 @@ async fn main() {
193208 log:: info!( "Ctrl+C/Exit signal received, shutting down" ) ;
194209 worker_task. abort( ) ;
195210 }
211+ _ = sigterm => {
212+ log:: info!( "SIGTERM received, shutting down" ) ;
213+ worker_task. abort( ) ;
214+ }
196215 }
197216 }
198217 }
You can’t perform that action at this time.
0 commit comments