Mountain/Track/Effect/CreateEffectForRequest/
Task.rs1use CommonLibrary::IPC::DTO::ProxyTarget::ProxyTarget;
2use serde_json::{Value, json};
3use tauri::Runtime;
4
5use crate::{
6 Track::Effect::{
7 CreateEffectForRequest::Utilities::{Params::val_at, Proxy::proxy_cocoon},
8 MappedEffectType::MappedEffect,
9 },
10 dev_log,
11};
12
13pub fn CreateEffect<R:Runtime>(MethodName:&str, Parameters:Value) -> Option<Result<MappedEffect, String>> {
14 match MethodName {
15 "Task.Fetch" => {
16 crate::effect!(run_time, {
17 let filter = val_at(&Parameters, 0);
18
19 proxy_cocoon(&run_time, ProxyTarget::ExtHostTaskService, "fetchTasks", json!([filter]), 5000)
20 .await
21 .or_else(|error| {
22 dev_log!("ipc", "warn: [Task.Fetch] extension did not answer ({:?}); returning []", error);
23
24 Ok(json!([]))
25 })
26 })
27 },
28
29 "Task.Execute" => {
30 crate::effect!(run_time, {
31 let task = val_at(&Parameters, 0);
32
33 proxy_cocoon(&run_time, ProxyTarget::ExtHostTaskService, "executeTask", json!([task]), 30000)
34 .await
35 .or_else(|error| {
36 dev_log!(
37 "ipc",
38 "warn: [Task.Execute] extension did not answer ({:?}); returning null",
39 error
40 );
41
42 Ok(json!(null))
43 })
44 })
45 },
46
47 "terminate_task" | "Task.Terminate" => {
54 crate::effect!(run_time, {
55 let execution = val_at(&Parameters, 0);
56
57 proxy_cocoon(
58 &run_time,
59 ProxyTarget::ExtHostTaskService,
60 "terminateTask",
61 json!([execution]),
62 5000,
63 )
64 .await
65 .or_else(|error| {
66 dev_log!(
67 "ipc",
68 "warn: [Task.Terminate] extension did not answer ({:?}); treating as no-op",
69 error
70 );
71
72 Ok(json!(null))
73 })
74 })
75 },
76
77 _ => None,
78 }
79}