ironflow_sdk/signal_methods.rs
1//! Signal methods for [`IronflowClient`].
2
3use ironflow_types::ApiResponse;
4
5use crate::client::{IronflowClient, ListSignalsFilter};
6use crate::error::Error;
7use crate::types;
8
9impl IronflowClient {
10 /// Send a signal, resuming every run waiting for its `(name, key)`.
11 ///
12 /// The caller must be an admin, or use an API key with the `signals_send`
13 /// scope. Sending again with the same `idempotency_id` delivers nothing
14 /// and returns `duplicate: true`.
15 ///
16 /// # Errors
17 ///
18 /// Returns an error if the HTTP request fails, the signal is invalid
19 /// (empty name or key), the caller lacks the permission, or the response
20 /// cannot be deserialized.
21 ///
22 /// # Examples
23 ///
24 /// ```no_run
25 /// use ironflow_sdk::IronflowClient;
26 /// use ironflow_sdk::types::SendSignalRequest;
27 /// use serde_json::json;
28 ///
29 /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
30 /// let client = IronflowClient::new("https://ironflow.example.com", "key");
31 /// let request: SendSignalRequest = serde_json::from_value(json!({
32 /// "name": "ci.pipeline_finished",
33 /// "key": "4f2a9c1",
34 /// "payload": {"status": "success"},
35 /// "idempotency_id": "delivery-42"
36 /// }))?;
37 /// let delivery = client.send_signal(&request).await?;
38 /// println!("{} runs resumed", delivery.data.resumed.len());
39 /// # Ok(())
40 /// # }
41 /// ```
42 pub async fn send_signal(
43 &self,
44 request: &types::SendSignalRequest,
45 ) -> Result<ApiResponse<types::SignalDeliveryResponse>, Error> {
46 self.send_envelope(self.post("/api/v1/signals").json(request))
47 .await
48 }
49
50 /// List received signals, newest first, with filters and pagination.
51 ///
52 /// # Errors
53 ///
54 /// Returns an error if the HTTP request fails or the response cannot be deserialized.
55 ///
56 /// # Examples
57 ///
58 /// ```no_run
59 /// use ironflow_sdk::IronflowClient;
60 /// use ironflow_sdk::client::ListSignalsFilter;
61 ///
62 /// # async fn example() -> Result<(), ironflow_sdk::Error> {
63 /// let client = IronflowClient::new("https://ironflow.example.com", "key");
64 /// let filter = ListSignalsFilter {
65 /// name: Some("ci.pipeline_finished".to_string()),
66 /// ..Default::default()
67 /// };
68 /// let signals = client.list_signals(&filter).await?;
69 /// # Ok(())
70 /// # }
71 /// ```
72 pub async fn list_signals(
73 &self,
74 filter: &ListSignalsFilter,
75 ) -> Result<ApiResponse<Vec<types::SignalResponse>>, Error> {
76 self.send_envelope(self.get("/api/v1/signals").query(filter))
77 .await
78 }
79}