Skip to main content

rocketmq_rust/
lib.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![feature(sync_unsafe_cell)]
16#![feature(async_fn_traits)]
17#![feature(unboxed_closures)]
18#![allow(dead_code)]
19
20mod arc_mut;
21mod blocking_queue;
22pub mod count_down_latch;
23pub mod rocketmq_tokio_lock;
24
25mod shutdown;
26pub mod task;
27
28pub mod schedule;
29
30pub use arc_mut::ArcMut;
31pub use arc_mut::SyncUnsafeCellWrapper;
32pub use arc_mut::WeakArcMut;
33pub use blocking_queue::BlockingQueue as RocketMQBlockingQueue;
34pub use count_down_latch::CountDownLatch;
35/// Re-export rocketmq main.
36pub use rocketmq::main;
37pub use rocketmq_tokio_lock::RocketMQTokioMutex;
38pub use rocketmq_tokio_lock::RocketMQTokioRwLock;
39pub use schedule::executor::ExecutorConfig;
40pub use schedule::executor::ExecutorPool;
41pub use schedule::executor::TaskExecutor;
42pub use schedule::scheduler::SchedulerConfig;
43pub use schedule::scheduler::TaskScheduler;
44pub use schedule::task::Task;
45pub use schedule::task::TaskContext;
46pub use schedule::task::TaskResult;
47pub use schedule::task::TaskStatus;
48pub use schedule::trigger::CronTrigger;
49pub use schedule::trigger::DelayTrigger;
50pub use schedule::trigger::DelayedIntervalTrigger;
51pub use schedule::trigger::IntervalTrigger;
52pub use schedule::trigger::Trigger;
53pub use shutdown::Shutdown;
54/// Re-export tokio module.
55pub use tokio as rocketmq;
56
57/// On unix platforms we want to intercept SIGINT and SIGTERM
58/// This method returns if either are signalled
59#[cfg(unix)]
60pub async fn wait_for_signal() {
61    use tokio::signal::unix::signal;
62    use tokio::signal::unix::SignalKind;
63    use tracing::info;
64    let mut term = signal(SignalKind::terminate()).expect("failed to register signal handler");
65    let mut int = signal(SignalKind::interrupt()).expect("failed to register signal handler");
66
67    tokio::select! {
68        _ = term.recv() => info!("Received SIGTERM"),
69        _ = int.recv() => info!("Received SIGINT"),
70    }
71}
72
73#[cfg(windows)]
74/// ctrl_c is the cross-platform way to intercept the equivalent of SIGINT
75/// This method returns if this occurs
76pub async fn wait_for_signal() {
77    let _ = tokio::signal::ctrl_c().await;
78}