Skip to main content

kernel_wake_run

Function kernel_wake_run 

Source
pub fn kernel_wake_run(event: &WakeEvent, app_name: &str) -> Result<NewRun>
Expand description

Builds the kernel.wake run a webhook or queue delivery enqueues: target KERNEL_WAKE_TARGET on the maintenance queue, keyed by event.key, with the event as input, acting as a Service subject (spec 3.2 §7.4).

The run’s user is the event’s principal, or the source’s name when the event carries none. NewRun::authenticated is set only when the event carries a principal, which a source sets only for a subject it verified (spec 3.1 I6).

§Example

use adk_kernel::{KERNEL_WAKE_TARGET, QueueClass, WakeEvent, kernel_wake_run};

let event = WakeEvent::new("hook:github", "hook:github:msg_1", serde_json::json!({"action": "opened"}));
let run = kernel_wake_run(&event, "adk-rust").unwrap();
assert_eq!(run.target, KERNEL_WAKE_TARGET);
assert_eq!(run.queue, QueueClass::MAINTENANCE);
assert_eq!(run.idempotency_key.as_deref(), Some("hook:github:msg_1"));
assert!(!run.authenticated);
assert_eq!(run.input["payload"]["action"], "opened");

§Errors

Returns KernelError::Serde when the event cannot be encoded, or KernelError::Core when the run is invalid, such as an event with an empty key or source.