kojin_core/
result_backend.rs1use async_trait::async_trait;
2
3use crate::error::{KojinError, TaskResult};
4use crate::task_id::TaskId;
5
6#[async_trait]
8pub trait ResultBackend: Send + Sync + 'static {
9 async fn store(&self, id: &TaskId, result: &serde_json::Value) -> TaskResult<()>;
11
12 async fn get(&self, id: &TaskId) -> TaskResult<Option<serde_json::Value>>;
14
15 async fn wait(
17 &self,
18 id: &TaskId,
19 timeout: std::time::Duration,
20 ) -> TaskResult<serde_json::Value>;
21
22 async fn delete(&self, id: &TaskId) -> TaskResult<()>;
24
25 async fn init_group(&self, _group_id: &str, _total: u32) -> TaskResult<()> {
27 Err(KojinError::ResultBackend(
28 "group operations not supported by this backend".into(),
29 ))
30 }
31
32 async fn complete_group_member(
34 &self,
35 _group_id: &str,
36 _task_id: &TaskId,
37 _result: &serde_json::Value,
38 ) -> TaskResult<u32> {
39 Err(KojinError::ResultBackend(
40 "group operations not supported by this backend".into(),
41 ))
42 }
43
44 async fn get_group_results(&self, _group_id: &str) -> TaskResult<Vec<serde_json::Value>> {
46 Err(KojinError::ResultBackend(
47 "group operations not supported by this backend".into(),
48 ))
49 }
50}