mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 01:08:28 +02:00
Add configurable timeouts for plugin events
- Add timeout parameter to send_to_plugins_and_wait and send_to_plugin_and_wait - Use 5 second timeout for standard operations (themes, actions, configs, etc.) - Use 5 minute timeout for user-interactive operations: - Authentication actions (OAuth login flows) - Authentication requests (token refresh, OAuth) - Template function calls (credential prompts, OAuth, etc.) - Fixes issue where auth flows would timeout after 5 seconds
This commit is contained in:
@@ -17,7 +17,6 @@ Review a GitHub pull request in a new git worktree.
|
|||||||
2. Get PR information using `gh pr view <PR_NUMBER> --json number,headRefName`
|
2. Get PR information using `gh pr view <PR_NUMBER> --json number,headRefName`
|
||||||
3. Extract the branch name from the PR
|
3. Extract the branch name from the PR
|
||||||
4. Create a new worktree at `../yaak-worktrees/pr-<PR_NUMBER>`
|
4. Create a new worktree at `../yaak-worktrees/pr-<PR_NUMBER>`
|
||||||
- IMPORTANT: Set a long timeout (600000ms = 10 minutes) for this command as the post-checkout hook runs npm install and bootstrap which can take several minutes
|
|
||||||
5. Checkout the PR branch in the new worktree using `gh pr checkout <PR_NUMBER>`
|
5. Checkout the PR branch in the new worktree using `gh pr checkout <PR_NUMBER>`
|
||||||
6. The post-checkout hook will automatically:
|
6. The post-checkout hook will automatically:
|
||||||
- Create `.env.local` with unique ports
|
- Create `.env.local` with unique ports
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ impl PluginManager {
|
|||||||
plugin_context,
|
plugin_context,
|
||||||
plugin,
|
plugin,
|
||||||
&InternalEventPayload::TerminateRequest,
|
&InternalEventPayload::TerminateRequest,
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -268,6 +269,7 @@ impl PluginManager {
|
|||||||
dir: plugin.directory.clone(),
|
dir: plugin.directory.clone(),
|
||||||
watch: !is_vendored && !is_installed,
|
watch: !is_vendored && !is_installed,
|
||||||
}),
|
}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -390,13 +392,20 @@ impl PluginManager {
|
|||||||
plugin_context: &PluginContext,
|
plugin_context: &PluginContext,
|
||||||
plugin: &PluginHandle,
|
plugin: &PluginHandle,
|
||||||
payload: &InternalEventPayload,
|
payload: &InternalEventPayload,
|
||||||
|
timeout_duration: Duration,
|
||||||
) -> Result<InternalEvent> {
|
) -> Result<InternalEvent> {
|
||||||
if !plugin.enabled {
|
if !plugin.enabled {
|
||||||
return Err(Error::PluginErr(format!("Plugin {} is disabled", plugin.metadata.name)));
|
return Err(Error::PluginErr(format!("Plugin {} is disabled", plugin.metadata.name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let events =
|
let events = self
|
||||||
self.send_to_plugins_and_wait(plugin_context, payload, vec![plugin.to_owned()]).await?;
|
.send_to_plugins_and_wait(
|
||||||
|
plugin_context,
|
||||||
|
payload,
|
||||||
|
vec![plugin.to_owned()],
|
||||||
|
timeout_duration,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(events
|
Ok(events
|
||||||
.first()
|
.first()
|
||||||
.ok_or(Error::PluginErr(format!(
|
.ok_or(Error::PluginErr(format!(
|
||||||
@@ -410,9 +419,10 @@ impl PluginManager {
|
|||||||
&self,
|
&self,
|
||||||
plugin_context: &PluginContext,
|
plugin_context: &PluginContext,
|
||||||
payload: &InternalEventPayload,
|
payload: &InternalEventPayload,
|
||||||
|
timeout_duration: Duration,
|
||||||
) -> Result<Vec<InternalEvent>> {
|
) -> Result<Vec<InternalEvent>> {
|
||||||
let plugins = { self.plugin_handles.lock().await.clone() };
|
let plugins = { self.plugin_handles.lock().await.clone() };
|
||||||
self.send_to_plugins_and_wait(plugin_context, payload, plugins).await
|
self.send_to_plugins_and_wait(plugin_context, payload, plugins, timeout_duration).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_to_plugins_and_wait(
|
async fn send_to_plugins_and_wait(
|
||||||
@@ -420,6 +430,7 @@ impl PluginManager {
|
|||||||
plugin_context: &PluginContext,
|
plugin_context: &PluginContext,
|
||||||
payload: &InternalEventPayload,
|
payload: &InternalEventPayload,
|
||||||
plugins: Vec<PluginHandle>,
|
plugins: Vec<PluginHandle>,
|
||||||
|
timeout_duration: Duration,
|
||||||
) -> Result<Vec<InternalEvent>> {
|
) -> Result<Vec<InternalEvent>> {
|
||||||
let label = format!("wait[{}.{}]", plugins.len(), payload.type_name());
|
let label = format!("wait[{}.{}]", plugins.len(), payload.type_name());
|
||||||
let (rx_id, mut rx) = self.subscribe(label.as_str()).await;
|
let (rx_id, mut rx) = self.subscribe(label.as_str()).await;
|
||||||
@@ -453,8 +464,8 @@ impl PluginManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Timeout after 10 seconds to prevent hanging forever if plugin doesn't respond
|
// Timeout to prevent hanging forever if plugin doesn't respond
|
||||||
if timeout(Duration::from_secs(5), collect_events).await.is_err() {
|
if timeout(timeout_duration, collect_events).await.is_err() {
|
||||||
warn!(
|
warn!(
|
||||||
"Timeout waiting for plugin responses. Got {}/{} responses",
|
"Timeout waiting for plugin responses. Got {}/{} responses",
|
||||||
found_events.len(),
|
found_events.len(),
|
||||||
@@ -492,6 +503,7 @@ impl PluginManager {
|
|||||||
.send_and_wait(
|
.send_and_wait(
|
||||||
&PluginContext::new(window),
|
&PluginContext::new(window),
|
||||||
&InternalEventPayload::GetThemesRequest(GetThemesRequest {}),
|
&InternalEventPayload::GetThemesRequest(GetThemesRequest {}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -513,6 +525,7 @@ impl PluginManager {
|
|||||||
.send_and_wait(
|
.send_and_wait(
|
||||||
&PluginContext::new(window),
|
&PluginContext::new(window),
|
||||||
&InternalEventPayload::GetGrpcRequestActionsRequest(EmptyPayload {}),
|
&InternalEventPayload::GetGrpcRequestActionsRequest(EmptyPayload {}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -534,6 +547,7 @@ impl PluginManager {
|
|||||||
.send_and_wait(
|
.send_and_wait(
|
||||||
&PluginContext::new(window),
|
&PluginContext::new(window),
|
||||||
&InternalEventPayload::GetHttpRequestActionsRequest(EmptyPayload {}),
|
&InternalEventPayload::GetHttpRequestActionsRequest(EmptyPayload {}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -555,6 +569,7 @@ impl PluginManager {
|
|||||||
.send_and_wait(
|
.send_and_wait(
|
||||||
&PluginContext::new(window),
|
&PluginContext::new(window),
|
||||||
&InternalEventPayload::GetWebsocketRequestActionsRequest(EmptyPayload {}),
|
&InternalEventPayload::GetWebsocketRequestActionsRequest(EmptyPayload {}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -576,6 +591,7 @@ impl PluginManager {
|
|||||||
.send_and_wait(
|
.send_and_wait(
|
||||||
&PluginContext::new(window),
|
&PluginContext::new(window),
|
||||||
&InternalEventPayload::GetWorkspaceActionsRequest(EmptyPayload {}),
|
&InternalEventPayload::GetWorkspaceActionsRequest(EmptyPayload {}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -597,6 +613,7 @@ impl PluginManager {
|
|||||||
.send_and_wait(
|
.send_and_wait(
|
||||||
&PluginContext::new(window),
|
&PluginContext::new(window),
|
||||||
&InternalEventPayload::GetFolderActionsRequest(EmptyPayload {}),
|
&InternalEventPayload::GetFolderActionsRequest(EmptyPayload {}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -663,6 +680,7 @@ impl PluginManager {
|
|||||||
context_id,
|
context_id,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
match event.payload {
|
match event.payload {
|
||||||
@@ -769,6 +787,7 @@ impl PluginManager {
|
|||||||
.send_and_wait(
|
.send_and_wait(
|
||||||
&plugin_context,
|
&plugin_context,
|
||||||
&InternalEventPayload::GetHttpAuthenticationSummaryRequest(EmptyPayload {}),
|
&InternalEventPayload::GetHttpAuthenticationSummaryRequest(EmptyPayload {}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -829,6 +848,7 @@ impl PluginManager {
|
|||||||
context_id,
|
context_id,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
match event.payload {
|
match event.payload {
|
||||||
@@ -882,6 +902,7 @@ impl PluginManager {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Duration::from_secs(300), // 5 minutes for OAuth flows
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -919,6 +940,7 @@ impl PluginManager {
|
|||||||
plugin_context,
|
plugin_context,
|
||||||
&plugin,
|
&plugin,
|
||||||
&InternalEventPayload::CallHttpAuthenticationRequest(req),
|
&InternalEventPayload::CallHttpAuthenticationRequest(req),
|
||||||
|
Duration::from_secs(300), // 5 minutes for OAuth flows
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
match event.payload {
|
match event.payload {
|
||||||
@@ -940,6 +962,7 @@ impl PluginManager {
|
|||||||
.send_and_wait(
|
.send_and_wait(
|
||||||
&plugin_context,
|
&plugin_context,
|
||||||
&InternalEventPayload::GetTemplateFunctionSummaryRequest(EmptyPayload {}),
|
&InternalEventPayload::GetTemplateFunctionSummaryRequest(EmptyPayload {}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -972,7 +995,11 @@ impl PluginManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let events = self
|
let events = self
|
||||||
.send_and_wait(plugin_context, &InternalEventPayload::CallTemplateFunctionRequest(req))
|
.send_and_wait(
|
||||||
|
plugin_context,
|
||||||
|
&InternalEventPayload::CallTemplateFunctionRequest(req),
|
||||||
|
Duration::from_secs(300), // 5 minutes for user interactions (OAuth, prompts, etc.)
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| RenderError(format!("Failed to call template function {e:}")))?;
|
.map_err(|e| RenderError(format!("Failed to call template function {e:}")))?;
|
||||||
|
|
||||||
@@ -1009,6 +1036,7 @@ impl PluginManager {
|
|||||||
&InternalEventPayload::ImportRequest(ImportRequest {
|
&InternalEventPayload::ImportRequest(ImportRequest {
|
||||||
content: content.to_string(),
|
content: content.to_string(),
|
||||||
}),
|
}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -1051,6 +1079,7 @@ impl PluginManager {
|
|||||||
filter: filter.to_string(),
|
filter: filter.to_string(),
|
||||||
content: content.to_string(),
|
content: content.to_string(),
|
||||||
}),
|
}),
|
||||||
|
Duration::from_secs(5),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user