pub struct UpdateCheckHandler { /* private fields */ }Expand description
TaskHandler that polls the GitHub releases API for a newer Zeph version.
On each execution, UpdateCheckHandler fetches the latest release from
https://api.github.com/repos/bug-ops/zeph/releases/latest, compares the
tag_name field against current_version using semantic versioning, and sends a
human-readable notification message on notify_tx when a newer release is found.
Network and parse errors are logged as warnings; execute always returns Ok(())
so a transient failure does not stop the scheduler.
§Examples
use tokio::sync::mpsc;
use zeph_scheduler::UpdateCheckHandler;
let (tx, mut rx) = mpsc::channel(1);
let handler = UpdateCheckHandler::new(env!("CARGO_PKG_VERSION"), tx);
use zeph_scheduler::TaskHandler;
handler
.execute(&serde_json::Value::Null)
.await
.expect("update check should not fail");
// A notification is sent only when a newer version exists on GitHub.
if let Ok(msg) = rx.try_recv() {
println!("{msg}");
}Implementations§
Source§impl UpdateCheckHandler
impl UpdateCheckHandler
Sourcepub fn new(current_version: &'static str, notify_tx: Sender<String>) -> Self
pub fn new(current_version: &'static str, notify_tx: Sender<String>) -> Self
Create a new handler.
current_version should be env!("CARGO_PKG_VERSION").
Notifications are sent as formatted strings via notify_tx.
§Panics
Panics if the underlying reqwest client cannot be constructed (unreachable in practice).
Sourcepub fn with_base_url(self, url: impl Into<String>) -> Self
pub fn with_base_url(self, url: impl Into<String>) -> Self
Override the GitHub releases API URL.
Intended for tests only: point the handler at a local mock server so the test does not make real network requests.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UpdateCheckHandler
impl !RefUnwindSafe for UpdateCheckHandler
impl Send for UpdateCheckHandler
impl Sync for UpdateCheckHandler
impl Unpin for UpdateCheckHandler
impl UnsafeUnpin for UpdateCheckHandler
impl !UnwindSafe for UpdateCheckHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more