Skip to content

Commit

Permalink
feat: Add runner delay to new request method
Browse files Browse the repository at this point in the history
This was intruced to upstream in usebruno#2218
  • Loading branch information
Its-treason committed Aug 10, 2024
1 parent 210f4fd commit ff21682
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1595,13 +1595,25 @@ export const collectionsSlice = createSlice({
info.status = 'ended';
}

if (type === 'request-queued') {
if (type === 'request-delayed') {
collection.runnerResult.items.push({
uid: request.uid,
status: 'queued'
status: 'delayed'
});
}

if (type === 'request-queued') {
const item = collection.runnerResult.items.findLast((i) => i.uid === request.uid);
if (item?.status === 'delayed') {
item.status = 'queued';
} else {
collection.runnerResult.items.push({
uid: request.uid,
status: 'queued'
});
}
}

if (type === 'request-sent') {
const item = collection.runnerResult.items.findLast((i) => i.uid === request.uid);
item.status = 'running';
Expand Down
23 changes: 19 additions & 4 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ const registerNetworkIpc = (mainWindow) => {
return scriptResult;
};

async function executeNewFolder(folder, collection, environment, recursive) {
async function executeNewFolder(folder, collection, environment, recursive, delay) {
const folderUid = folder ? folder.uid : null;
const dataDir = path.join(app.getPath('userData'), 'responseCache');
const cancelToken = uuid();
Expand Down Expand Up @@ -462,6 +462,23 @@ const registerNetworkIpc = (mainWindow) => {
let currentRequestIndex = 0;
let nJumps = 0; // count the number of jumps to avoid infinite loops
while (currentRequestIndex < folderRequests.length) {
const item = folderRequests[currentRequestIndex];

if (!isNaN(delay) && delay > 0) {
// Send the queue event so ui shows its loading
mainWindow.webContents.send('main:run-folder-event', {
type: 'request-delayed',
itemUid: item.uid,
collectionUid: collection.uid,
folderUid
});

await new Promise((resolve) => {
abortController.signal.addEventListener('abort', resolve);
setTimeout(() => resolve(), delay);
});
}

if (abortController.signal.aborted) {
deleteCancelToken(cancelToken);
mainWindow.webContents.send('main:run-folder-event', {
Expand All @@ -473,8 +490,6 @@ const registerNetworkIpc = (mainWindow) => {
return;
}

const item = folderRequests[currentRequestIndex];

const res = await newRequest(
item,
collection,
Expand Down Expand Up @@ -1013,7 +1028,7 @@ const registerNetworkIpc = (mainWindow) => {
'renderer:run-collection-folder',
async (event, folder, collection, environment, runtimeVariables, recursive, delay, newRequestMethod) => {
if (newRequestMethod) {
return await executeNewFolder(folder, collection, environment, recursive);
return await executeNewFolder(folder, collection, environment, recursive, delay);
}

const collectionUid = collection.uid;
Expand Down

0 comments on commit ff21682

Please sign in to comment.