Skip to main content

Crate slung

Crate slung 

Source
Expand description

§Slung Rust SDK

An abstraction library for interacting with the Slung runtime.

§Quickstart

Add to your rust project’s Cargo.toml:

[dependencies]
slung = "0.1.0"

And then at the top of your module:

use slung::prelude::*;

§Example

Here’s a basic anomaly detection example:

use slung::prelude::*;

#[main]
fn main() -> Result<()> {
    // Subscribe to live stream updates.
    let handle = query_live("AVG:temp:[sensor=1]")?;
    poll_handle(handle, on_event, 100.0)?;

    Ok(())
}

fn on_event(event: Event, alert_threshold: f64) -> Result<()> {
    if event.value > alert_threshold {
        println!("event timestamp={} value={}", event.timestamp, event.value);
        for producer in event.producers {
            writeback_ws(producer, "ALERT: threshold exceeded")?;
        }
    }

    Ok(())
}

§Query Syntax

OP:SERIES:[TAGS]:[RANGE]

  • RANGE is optional
  • OP: AVG, MIN, MAX, SUM, COUNT
  • TAGS: AND, OR, NOT
  • RANGE: [start_time,end_time]. Timestamps in microseconds. Also supports sec, min, hour, day, week (short & plural forms apply).

§License

Unlike the root project, this SDK is licensed under the MIT License - see the LICENSE file for details.

Modules§

prelude
Common imports for workflow handlers.

Structs§

Avg
Running average state.
Event
Event payload returned by host polling.

Enums§

PollState
Polled aggregate state variants.
WritebackMethod
HTTP method mapping expected by the host writeback API.

Functions§

free_handle
Free a live query handle on the host.
poll_handle
Poll a live query forever and invoke callback for each received event.
poll_handle_state
Poll a live query once and decode aggregate state if available.
query_history
Execute a historical aggregation query and return the aggregate value.
query_live
Register a live query and return its host handle.
unix_micros
Return the current Unix epoch timestamp in microseconds.
write_event
Write a new event to the host.
writeback_http
Send an HTTP writeback request through the host.
writeback_ws
Write back text data to a websocket producer destination.

Type Aliases§

QueryHandle
Opaque handle returned by live-query registration.