Jon/sky 6395 refresh code while workflow is running (#3444)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user