Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not delete the AgentUserRelation #8246

Closed
wants to merge 3 commits into from

Conversation

flvndvd
Copy link
Contributor

@flvndvd flvndvd commented Oct 25, 2024

Description

This PR updates the existing remove draft agent configuration scripts to avoid deleting the UserAgentRelation.

I took the opportunity to add some concurrency by bringing concurrentExecutor in types. We have an existing implementation in connectors that uses p-queue 🤮. This one is pure TS.

Will update connectors to use this new implementation.

Risk

Deploy Plan

* @param options.concurrency - Maximum number of parallel executions (default: 8)
* @returns Promise resolving to array of results in the same order as input items.
*/
export async function concurrentExecutor<T, V>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with:

async function main() {
  const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

  console.log("Starting execution...");

  const results = await concurrentExecutor(
    items,
    async (item, idx) => {
      console.log(`Starting task ${idx} (value: ${item})`);

      // Random delay.
      const delay = Math.floor(Math.random() * 2000) + 1000;
      await new Promise((resolve) => setTimeout(resolve, delay));

      console.log(`Completed task ${idx} (value: ${item}) after ${delay}ms`);
      return item * 2;
    },
    { concurrency: 3 }
  );

  console.log("All tasks completed!");
  console.log("Results:", results);
}

main().catch(console.error);

Yields:

Starting execution...
Starting task 0 (value: 1)
Starting task 1 (value: 2)
Starting task 2 (value: 3)
Completed task 1 (value: 2) after 1213ms
Starting task 3 (value: 4)
Completed task 2 (value: 3) after 1592ms
Starting task 4 (value: 5)
Completed task 3 (value: 4) after 1571ms
Starting task 5 (value: 6)
Completed task 0 (value: 1) after 2803ms
Starting task 6 (value: 7)
Completed task 4 (value: 5) after 1259ms
Starting task 7 (value: 8)
Completed task 7 (value: 8) after 2066ms
Starting task 8 (value: 9)
Completed task 6 (value: 7) after 2322ms
Starting task 9 (value: 10)
Completed task 5 (value: 6) after 2557ms
Completed task 9 (value: 10) after 1817ms
Completed task 8 (value: 9) after 2269ms
All tasks completed!
Results: [
   2,  4,  6,  8, 10,
  12, 14, 16, 18, 20
]

@Fraggle
Copy link
Contributor

Fraggle commented Oct 25, 2024

I took the opportunity to add some concurrency by bringing concurrentExecutor in types. We have an existing implementation in connectors that uses p-queue 🤮. This one is pure TS.

WHyyyyyyyy oh whyyy ? :)

(more seriously, if we already had one way, why add another way ?)

@flvndvd
Copy link
Contributor Author

flvndvd commented Oct 28, 2024

I took the opportunity to add some concurrency by bringing concurrentExecutor in types. We have an existing implementation in connectors that uses p-queue 🤮. This one is pure TS.

WHyyyyyyyy oh whyyy ? :)

(more seriously, if we already had one way, why add another way ?)

p-queue isn't a dependency of front and we had some bundling issue in the past with their library.

@flvndvd flvndvd closed this Nov 26, 2024
@flvndvd flvndvd deleted the flav/fix-remove-draft-agent-configurations branch November 26, 2024 08:12
@flvndvd flvndvd restored the flav/fix-remove-draft-agent-configurations branch December 2, 2024 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants