Jon/sky 6395 refresh code while workflow is running (#3444)

This commit is contained in:
Jonathan Dobson
2025-09-16 14:47:09 -04:00
committed by GitHub
parent ca84e57665
commit d57fccfaaf
4 changed files with 98 additions and 40 deletions

View File

@@ -7,17 +7,25 @@ type Props = {
cacheKey?: string;
cacheKeyValue?: string;
workflowPermanentId?: string;
pollIntervalMs?: number;
};
function useBlockScriptsQuery({
cacheKey,
cacheKeyValue,
workflowPermanentId,
pollIntervalMs,
}: Props) {
const credentialGetter = useCredentialGetter();
return useQuery<{ [blockName: string]: string }>({
queryKey: ["block-scripts", workflowPermanentId, cacheKey, cacheKeyValue],
queryKey: [
"block-scripts",
workflowPermanentId,
cacheKey,
cacheKeyValue,
pollIntervalMs,
],
queryFn: async () => {
const client = await getClient(credentialGetter, "sans-api-v1");
@@ -30,6 +38,12 @@ function useBlockScriptsQuery({
return result.blocks;
},
refetchInterval: () => {
if (!pollIntervalMs || pollIntervalMs === 0) {
return false;
}
return Math.max(2000, pollIntervalMs);
},
enabled: !!workflowPermanentId,
});
}