Skip to main content

Module runtime

Module runtime 

Source
Expand description

SZ-Rust Runtime — Swoole/Worker 适配主入口

§PHP 对齐

对齐 PHP topthink/think-swoole 的运行时模型:

PHP SwooleRust SZ-Rust说明
Swoole\Runtime::enableCoroutine()SzRuntime::block_on(fut)协程入口
swoole_cpu_num()num_cpus::get()默认 worker 数
worker_num 配置项SzRuntime::with_worker_threads(n)自定义 worker 数
Swoole\Process::signal()tokio::signal + CancellationToken信号处理
Swoole\Timer::tick()tokio::time::interval + tokio::select!定时任务
swoole_event::defer()SzRuntime::spawn(fut)异步任务

§模块结构

模块对齐 PHP子任务
runtime::workerworker_num 配置9.2
runtime::spawnswoole_event::defer9.3
runtime::queuethink-queue 消费者9.4
runtime::mqtt长连接9.5
runtime::websocketthink-worker9.6
runtime::schedulerCrontab9.7
runtime::shutdown优雅关闭9.8
runtime::signalSIGTERM/SIGINT9.9

§关键决策

  • 不修改 sz-orm-scheduler 内部 API:保持 CronScheduler::start()/stop() 向后兼容, 在 sz-rust 侧用 tokio::time::interval + try_fire_due() 重写循环。
  • 使用 CancellationToken 统一关闭广播:替代 AtomicBool + oneshot,支持父子层级。
  • 双平台信号处理:Unix 用 SignalKind::terminate/interrupt,Windows 用 ctrl_c/ctrl_close

Re-exports§

pub use mqtt::MqttRuntime;
pub use mqtt::MqttRuntimeConfig;
pub use queue::QueueConsumer;
pub use queue::QueueRuntime;
pub use queue::QueueRuntimeConfig;
pub use scheduler::SchedulerRuntime;
pub use shutdown::GracefulShutdown;
pub use signal::shutdown_signal;
pub use spawn::spawn_with_token;
pub use websocket::WebSocketRuntime;
pub use websocket::WebSocketRuntimeConfig;
pub use worker::WorkerConfig;

Modules§

mqtt
sz-orm-mqtt 长连接接入
queue
sz-orm-queue 消费者接入
scheduler
定时任务调度接入
shutdown
优雅关闭协调器
signal
信号处理
spawn
tokio::spawn 异步任务
websocket
sz-orm-websocket 服务端接入
worker
Worker 数量配置

Structs§

SzRuntime
SZ-Rust 异步运行时