use crate::client::WorkerApiClient;
use crate::error::ClientError;
use serde_json::Value;
use uuid::Uuid;
#[derive(Clone)]
pub struct ActivityContext {
pub workflow_id: Uuid,
pub activity_id: Uuid,
pub activity_key: String,
pub signal: Option<Value>,
worker_id: String,
client: Option<WorkerApiClient>,
}
impl ActivityContext {
pub fn new(workflow_id: Uuid, activity_id: Uuid, activity_key: impl Into<String>) -> Self {
Self {
workflow_id,
activity_id,
activity_key: activity_key.into(),
signal: None,
worker_id: String::new(),
client: None,
}
}
pub fn with_signal(mut self, signal: Option<Value>) -> Self {
self.signal = signal;
self
}
pub fn with_client(mut self, client: WorkerApiClient, worker_id: impl Into<String>) -> Self {
self.client = Some(client);
self.worker_id = worker_id.into();
self
}
pub fn worker_id(&self) -> &str {
&self.worker_id
}
pub async fn heartbeat(&self) -> Result<(), ClientError> {
if let Some(client) = &self.client {
client.heartbeat(self.activity_id, &self.worker_id).await?;
}
Ok(())
}
}